Can I call commit from one of mutations in Vuex store

后端 未结 12 1068
醉酒成梦
醉酒成梦 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:17

    Reading the Vuex documentation on Actions, it's quite clear what they are made for.

    • commit mutations instead of mutating the state
    • can contain arbitrary asynchronous operations

    Actions can (not must) contain asynchronous code. In fact, the following example is correct

    increment (context) {
       context.commit('increment')
    }
    

    I do not see any issue in using actions for performing multiple mutations.

提交回复
热议问题