Sometimes, we want to dispatch actions between two namespaced Vuex modules.
In this article, we’ll look at how to dispatch actions between two namespaced Vuex modules.
How to dispatch actions between two namespaced Vuex modules?
To dispatch actions between two namespaced Vuex modules, we can call dispatch
with the module name prefixed to the action method and the root
option set to true
.
For instance, we write
dispatch(
"notification/triggerNotifcation",
{
//...
},
{ root: true }
);
to dispatch the notification/triggerNotifcation
action which is in the notification
module.
And we set root
to true
to let us dispatch actions from any module and namespace.
Conclusion
To dispatch actions between two namespaced Vuex modules, we can call dispatch
with the module name prefixed to the action method and the root
option set to true
.