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

前端 未结 1 1713
渐次进展
渐次进展 2020-12-12 10:55

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 di

相关标签:
1条回答
  • 2020-12-12 11:30

    You just need to specify that you're dispatching from the root context:

    // from the gameboard.js vuex module
    dispatch('notification/triggerSelfDismissingNotifcation', {...}, {root:true})
    

    Now when the dispatch reaches the root it will have the correct namespace path to the notifications module (relative to the root instance).

    This is assuming you're setting namespaced: true on your vuex store module.

    0 讨论(0)
提交回复
热议问题