Reputation: 4172
I have a Vuex store object which has a mutation.
SET_FILTERS_CATEGORIES(state, payload) {
state.filters.categories = payload;
},
SET_FILTERS_CATEGORIES(state, payload) {
// state.filters.categories = payload; // This "works"
},
This mutation throws me an error:
do not mutate vuex store state outside mutation handlers
If I commented this line it "works". I dont understand what is the problem. It is inside the mutation section.
Upvotes: 0
Views: 850
Reputation: 564
you must call your mutation only inside action method.
code exemple
const mutations = {
SET_FILTERS_CATEGORIES(state, payload) {
state.filters.categories = payload;
},
}
const actions = {
getFiltersCategories ({commit}, payload){
commit('SET_FILTERS_CATEGORIES', payload)
}
}
Upvotes: 1