vue.js - 在 mapActions() 中找不到 Vuex 模块命名空间

标签 vue.js vuejs2 vuex

尝试从我的商店调用操作时出现以下错误:

[vuex] module namespace not found in mapActions(): feedbacksessionStore/



从我在网上发现的其他解决方案中,人们建议设置“命名空间:真”,但这对我的情况没有帮助。

这是我的商店代码片段:
export const feedbackSessionStore = {
    namespaced: true,

    state: {
        feedback_sessions: {},
    },

    actions: {

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

以及组件代码片段:

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

// some code

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

最佳答案

作为解决此问题的方法,您必须做两件事:

  • 通过在 store/modules 目录中执行以下代码,将“feedbackSessionStore.js”作为单独的模块:
    namespaced: true,
    
    state: {
        feedback_sessions: {},
    },
    
    actions: {
    
        async createFeedbackSession({commit, state}, { data }) {
          // some code
        }
    }
    
  • 像这样将此模块添加到 store/index.js 中:
    import * as feedbackSessionStore from "@/store/modules/feedbackSessionStore.js";
    

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

    关于vue.js - 在 mapActions() 中找不到 Vuex 模块命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62255212/

    相关文章:

    vue.js - 无法在 nuxtjs api 调用中读取未定义的属性(读取 'weather' )

    vue.js - 从外部文件导入 Vuex 实例时无法访问 $store

    javascript - 我应该如何正确调用NuxtServerInit?

    css - 如何将 SASS "normal way"与 vue.js 一起使用?

    javascript - 数据变化随机更新 - Vue/Vuex

    javascript - 如何在异步函数上使用 debounce?

    javascript - 将dir rtl属性添加到vuejs中的html标签

    javascript - 在 Nuxt 中设置输出文件夹的路径

    laravel - VeeValidate 即使使用键也验证不存在的字段错误

    vue.js - 如何使用 Prop 值初始化数据属性