Vuex | How to fix a global mutation in a module action?

I have an action in a module with names and a global mutation (i.e. not in a module). I would like to be able to capture a global mutation within an action.

// Global mutation
export default {
  globalMutation (state, payload) {
    ...
  }
}

// Action in a namespaced module
export default {
  namespaced: true,

  actions: {
    namespacedAction ({ commit, dispatch, state }, payload) {
      commit({ type: 'globalMutation' })
    }
  }
}

When an action with names is dispatched, Vuex displays:

[vuex] unknown local mutation type: globalMutation, global type: module/globalMutation

Is there an option that I can pass functions committo call this global mutation?

+6
source share
1 answer

Looks like I just found a way with a parameter { root: true }.

commit('globalMutation', payload, { root: true })
+12
source

All Articles