I'm trying to update a state from another module. The structure is.
store.js
|
|-- yields.js
|
|--analysis (sub-folder)
|
|
---actions.js
|
---mutations.js
|
---state.js
So as suggested I used this in actions.js:
export const actions = {
analysisAction({
commit,
rootState
}, input) {
commit('stateFetchParamsStart', input); // Commit in this module
commit('yields/statePRdate', input, {
root: true
}); // Commit in another module
},...
Added a mutation in yields.js:
const mutations = {
statePRdate: (state, input) => {
state.PRdate = input;
},...
And call it in a computed property like:
computed: {
start: {
get() {
return this.$store.state.analysis.fetchParams.start
},
set(value) {this.$store.dispatch('analysisAction', value);
}
},...
methods: {
...mapActions([
'otherActions',
'analysisAction'
]),
I also tried the namespaced variant, but it's giving me an error. With this solution the mutation for state.fetchParams.start
is working but I get the error: [vuex] unknown mutation type: yields/statePRdate
So it cant call the mutation of the other state.