How to submit global changes in module operations: Vuex
P粉321584263
P粉321584263 2023-08-23 08:53:48
0
1
487
<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粉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!