Can I call commit from one of mutations in Vuex store

后端 未结 12 1186
醉酒成梦
醉酒成梦 2021-02-03 16:25

I have a vuex store, like following:

import spreeApi from \'../../gateways/spree-api\'
// initial state
const state = {
  products: [],
  categories: []
}

// mu         


        
12条回答
  •  無奈伤痛
    2021-02-03 17:07

    If you absolutely must commit two mutations, why not do it from an action? Actions don't have to perform async operations. You can destructure the commit method in your action the same way you do with state like so:

    commitTwoThings: ({commit}, payload) => {
      commit('MUTATION_1', payload.thing)
      commit('MUTATION_2', payload.otherThing)
    }
    

提交回复
热议问题