【问题标题】:Nuxt.js Store, dispatch action to other storeNuxt.js 存储,将操作发送到其他存储
【发布时间】:2019-01-20 20:54:00
【问题描述】:

我的 Nuxt.js 应用上有两个商店,我需要向另一个商店发送操作。

export const actions = {
   addToCart({ state, commit, dispatch }) {
    dispatch('CartLoadingStore/enableLoadingBar')

    this.$axios
      .post('something')
      .then(response => {
        (...)
        dispatch('CartLoadingStore/disableLoadingBar')
      })
  },
}

在我看来,我无法将操作发送到不同的商店。是对的吗?或者有什么办法吗?

以上会导致错误:

[vuex] unknown local action type: CartLoadingStore/enableLoadingBar, global type: StoreTheActionDispatchedFrom/CartLoadingStore/enableLoadingBar

【问题讨论】:

    标签: vue.js vuex nuxt.js


    【解决方案1】:

    您需要将根参数添加到您的调度调用中

    dispatch('CartLoadingStore/disableLoadingBar', null, { root: true })
    

    这里docs

    【讨论】:

    • 感谢 Aldarund。有这方面的文件吗?在 nuxt 文档中找不到任何内容..
    • @mauxtin 我用文档链接更新了答案。由于它的 vuex,它在 vuex 的文档中声明
    猜你喜欢
    • 2018-09-01
    • 2018-05-06
    • 2021-12-07
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 2014-12-03
    相关资源
    最近更新 更多