Home  >  Q&A  >  body text

How to submit global changes in module operations: Vuex

<p>I have an action and a global change in a namespace module (i.e. not in the module). I want to be able to commit global changes in the action. </p> <pre class="brush:php;toolbar:false;">//Global changes export default { globalMutation (state, payload) { ... } } //Actions in namespace modules export default { namespaced: true, actions: { namespacedAction ({ commit, dispatch, state }, payload) { commit({ type: 'globalMutation' }) } } }</pre> <p>When dispatching a namespace action, Vuex displays: </p> <pre class="brush:php;toolbar:false;">[vuex] unknown local mutation type: globalMutation, global type: module/globalMutation</pre> <p>Can I invoke this global change by passing an option to the <code>commit</code> function? </p>
P粉321584263P粉321584263445 days ago532

reply all(1)I'll reply

  • P粉489081732

    P粉4890817322023-08-24 00:46:15

    Looks like I just found a way to do this using the { root: true } parameter.

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

    If the module has a namespace, use the global path instead:

    commit('module/mutation', payload, { root: true })

    reply
    0
  • Cancelreply