How to submit global changes in module operations: Vuex
P粉321584263
P粉321584263 2023-08-23 08:53:48
0
1
470

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.

//Global changes export default { globalMutation (state, payload) { ... } } //Actions in namespace modules export default { namespaced: true, actions: { namespacedAction ({ commit, dispatch, state }, payload) { commit({ type: 'globalMutation' }) } } }

When dispatching a namespace action, Vuex displays:

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

Can I invoke this global change by passing an option to the commit function?

P粉321584263
P粉321584263

reply all (1)
P粉489081732

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 })
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!