我的 Nuxt.js 应用程序上有两个商店,我需要将一个操作分派到另一个商店。
export const actions = {
addToCart({ state, commit, dispatch }) {
dispatch('CartLoadingStore/enableLoadingBar')
this.$axios
.post('something')
.then(response => {
(...)
dispatch('CartLoadingStore/disableLoadingBar')
})
},
}
Run Code Online (Sandbox Code Playgroud)
在我看来,我无法将操作发送到不同的商店。那正确吗?或者有没有办法这样做?
以上将导致错误:
[vuex] unknown local action type: CartLoadingStore/enableLoadingBar, global type: StoreTheActionDispatchedFrom/CartLoadingStore/enableLoadingBar
Run Code Online (Sandbox Code Playgroud)
Ald*_*und 11
您需要在调度调用中添加根参数
dispatch('CartLoadingStore/disableLoadingBar', null, { root: true })
Run Code Online (Sandbox Code Playgroud)
这里的文档
| 归档时间: |
|
| 查看次数: |
3531 次 |
| 最近记录: |