Is there a way to dispatch actions between two namespaced vuex modules?

Is it possible to dispatch an action between namespaced modules?

E.g. I have Vuex modules “gameboard” and “notification”. Each are namespaced. I would like to dispatch an action from the gameboard module in the notification module.

I thought I could use the module name in the dispatch action name like this:

// store/modules/gameboard.js
const actions = {
    myaction ({dispatch}) {
        ...
        dispatch('notification/triggerSelfDismissingNotifcation', {...})
    }
}
// store/modules/notification.js
const actions = {
    triggerSelfDismissingNotification (context, payload) {
        ...
    }
}

But when I try to do this I get errors that make me think Vuex is trying to dispatch an action within my gameboard module:

[vuex] unknown local action type: notification/triggerSelfDismissingNotification, global type: gameboard/notification/triggerSelfDismissingNotification

Is there a way of dispatching actions from a given Vuex module to another, or do I need to create some kind of a bridge in the root Vuex instance?

2 Answers
2

Leave a Comment