Chr*_*itz 113 vue.js vuex vuejs2
是否可以在命名空间模块之间调度操作?
例如,我有vuex模块"gameboard"和"notification".每个都是命名空间.我想从游戏板向通知模块发送一个动作.
我以为我可以在调度操作名称中使用模块名称,如下所示:
// store/modules/gameboard.js
const actions = {
myaction ({dispatch}) {
...
dispatch('notification/triggerSelfDismissingNotifcation', {...})
}
}
// store/modules/notification.js
const actions = {
triggerSelfDismissingNotification (context, payload) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试这样做时,我得到的错误让我觉得vuex试图在我的游戏板模块中发送一个动作:
[vuex] unknown local action type:notification/triggerSelfDismissingNotification,global type:gameboard/notification/triggerSelfDismissingNotification
有没有从vuex模块调度到模块的方法,还是需要在root vuex实例中创建某种桥接?
Jak*_*ake 253
您只需要指定从根上下文调度:
// from the gameboard.js vuex module
dispatch('notification/triggerSelfDismissingNotifcation', {...}, {root:true})
Run Code Online (Sandbox Code Playgroud)
现在,当调度到达根时,它将具有通知模块的正确命名空间路径(相对于根实例).
假设您正在设置namespaced: truevuex商店模块.
| 归档时间: |
|
| 查看次数: |
43036 次 |
| 最近记录: |