Can I call commit from one of mutations in Vuex store

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

    First, assign the Vue button to a variable: In main.js:

      export const app = new Vue({  
      router,
      vuetify,
      store,....
    

    Then import the "app" variable to the js file where you define the mutation: In modules.js:

    import { app } from "../../main";
    

    You can now use it as "app.$store.commit":

    mutations: {
    [AUTH_SET_TOKEN]: () => {
    app.$store.commit(USER_SUCCESS, params );
    },...
    

提交回复
热议问题