Can I call commit from one of mutations in Vuex store
Can I call commit from one of mutations in Vuex store
By using mutation, there is no way to commit another mutation. A mutation is a synchronous call which changes the state. Within one mutation, It is not able to commit another mutation.
vuex reference: https://vuex.vuejs.org/en/api.html
As you can see, a mutation handler receives only state and payload. Therefore getting commit as undefined.
Incase to set the PRODUCT and CATEGORIES as part of the similiar mutation handler as a single commit.
// mutations const mutations = { SET_PRODUCTS_AND_CATEGORIES: (state, response) => { state.products = response.data.products state.categories = state.products.map(function(product) { return product.category}) }, // ... }