【问题标题】:Vuex module namespace not found in mapActions()在 mapActions() 中找不到 Vuex 模块命名空间
【发布时间】:2020-09-27 00:19:49
【问题描述】:

我在尝试从我的商店调用操作时收到以下错误:

[vuex] 在 mapActions() 中找不到模块命名空间: 反馈sessionStore/

从我在网上找到的其他解决方案中,人们建议设置“namespaced: true”,但不知何故这对我的情况没有帮助。

这是我的商店代码的sn-p:

export const feedbackSessionStore = {
    namespaced: true,

    state: {
        feedback_sessions: {},
    },

    actions: {

        async createFeedbackSession({commit, state}, { data }) {
          // some code
        }
    }
}

以及组件代码的sn-p:


import { mapGetters, mapState, mapActions } from 'vuex'

// some code

export default {
  name: 'create-edit-feedback-session',
  methods: {
    ...mapActions('feedbackSessionStore', [
        'createFeedbackSession'
    ]),
    // some code
}

【问题讨论】:

  • 你注册了吗?喜欢将其添加到商店?

标签: vue.js vuejs2 vuex


【解决方案1】:

为了解决这个问题,你必须做两件事:

  1. 通过在 store/modules 目录中执行以下代码,将“feedbackSessionStore.js”作为一个单独的模块:

    namespaced: true,
    
    state: {
        feedback_sessions: {},
    },
    
    actions: {
    
        async createFeedbackSession({commit, state}, { data }) {
          // some code
        }
    }
    
  2. 像这样将该模块添加到 store/index.js 中:

    import * as feedbackSessionStore from "@/store/modules/feedbackSessionStore.js";
    

在这两个步骤之后,它应该可以工作了。

【讨论】:

    猜你喜欢
    • 2021-05-17
    • 1970-01-01
    • 2020-03-29
    • 2019-01-21
    • 2020-07-24
    • 2020-07-14
    • 2019-02-26
    • 2018-05-27
    • 2020-05-07
    相关资源
    最近更新 更多