Categories
Vue Answers

How to dispatch actions between two namespaced Vuex modules?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *