Capsuled Data Sharing With Vuex, Axios & Several Component Instances
I have a component QuestionContainer.vue with several questions (input forms). Every user given answer (user input) is validated in realtime (@keyup.prevent='keyUpRoutine(questionk
Solution 1:
I had a similar issue, where I had to store the state of multiple instances of the same component. So currently your mutations update single properties in the store. Instead of doing this, my approach is to create an array of objects for this state. For instance, you mutation should work like this: App.js
context.commit("SET_OBLIGATION_STATE", {index: 0, value: "valid"});
store/state.js
// You can instantiate it with all your instances of this component or add them dynamically
{ obligationState: [ { value: "valid" } ] }
store/mutation.js
SET_OBLIGATION_STATE(state, payload) {
Vue.set(state.obligationState, payload.index, payload.value)
},
QuestionContainer.vue
// You can pass here the index of your component instance and then 'checkObligationConsistency' action will know which instance state to updatethis.$store.dispatch("checkObligationConsistency", { someData, index })
Post a Comment for "Capsuled Data Sharing With Vuex, Axios & Several Component Instances"