Purpose of vue.js components
- Aim of DataTable component is to display backend database' data.
- Aim of NewDataPanel.vue component is to add data to backend database.
Required behavior
After creating new data via NewDataPanel it should appear in backend database and at the DataTable.
Problem
After creating new data they appears in backend database but there is a problem with refreshing DataTable component.
As required methods are in sequence:
this.$store.dispatch('postResult')
this.$store.dispatch('getResult')
it's supposed that some data would first created and then all data would be retrieved from backend and the store would be mutated to display refreshed data at DataTable.
But after adding first data element nothing happened with DataTable. And only after adding second data element the first one would appear here.
How should I realize DataTable refreshing after adding new data?
P.S.: Sources and components diagram are below.
DataTable.vue
export default {
// ...
computed: {
// ...
...mapGetters(['resultTable'])
// ...
}
// ...
beforeMount () {
this.$store.dispatch('getResult')
}
}
NewDataPanel.vue
export default {
// ...
methods: {
// ...
addData () {
// ...
this.$store.dispatch('postResult')
this.$store.dispatch('getResult')
// ...
}
// ...
}
// ...
}
vuex store's actions work with Django Rest Framework via API:
postResult just send JSON to backend, where data saved
getResult gets list of serialized objects and mutate state.resultTable with that data
vuex' store.js
actions = {
getResult ({commit}, payload) {
Result.getResult(payload).then(result => {
commit(GET_RESULT, {result})
})
},
postResult ({commit}, payload) {
Result.postResult(payload)
}
}