FrontendDeveloper.in

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.

  1. 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
}
}
}
  1. In actions, local state will be available as first argument.
const moduleOne = {
actions: {
incrementConditional ({ state, commit, rootState }) {
if (state.count < rootState.count) {
commit('increment')
}
}
}
}
Back to all Vue.js questions
Get LinkedIn Premium at Rs 399