Vue.js question detail
What is module local state?
When you use modules the local state will be available to mutations, getters and actions in different ways.
- Both mutations and getters will receive module local state as first argument.
const moduleOne = {
state: { count: 0 },
mutations: {
increment (state) {
state.count++; // Here state refers local module state
}
},
getters: {
average (state) {
return state.count / 2
}
}
}
- In actions, local state will be available as first argument.
const moduleOne = {
actions: {
incrementConditional ({ state, commit, rootState }) {
if (state.count < rootState.count) {
commit('increment')
}
}
}
}