gpt4 book ai didi

vue.js - Vuex:在 mapState() 中找不到 [vuex] 模块命名空间 | mapGetters(): X/

转载 作者:行者123 更新时间:2023-12-03 06:39:31 24 4
gpt4 key购买 nike

根据 Vuex 文档模块化组织存储( https://vuex.vuejs.org/guide/modules.html ),我有以下内容:
store/index.js :

import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

// Default Store State for the Hug Employee Dashboard:
// import defaultState from "@/store/defaultStore";

/*eslint no-param-reassign: ["error", { "props": false }]*/
/*eslint indent: ["error", 2]*/
/*eslint arrow-body-style: ["error", "always"]*/
/*eslint-env es6*/

const surfGroups = {
state: {
activeSurfGroup: {},
fetchingSurfGroupLoading: false,
creatingSurfGroupLoading: false
},
getters: {
activeSurfGroup: state => {
return state.activeSurfGroup;
},
},
mutations: {
// API Request Mutations:
SET_ACTIVE_SURF_GROUP(state, payload) {
this.activeSurfGroup = payload;
},
// Loading Mutations:
SET_FETCHING_SURF_GROUP_LOADING(state, payload) {
state.fetchingSurfGroupLoading = payload;
},
SET_CREATING_SURF_GROUP_LOADING(state, payload) {
state.creatingSurfGroupsLoading = payload;
}
},
actions: {
fetchSurfGroup: async ({ commit }, payload) => {
commit("SET_FETCHING_SURF_GROUP_LOADING", true);
// Dispatches the following Surf Levels API service:
// this.$surfLevelsAPI.fetchActiveSurfGroup(
// payload.activeSurfGroupUUID
// );
await Vue.prototype.$surfLevelsAPI.fetchActiveSurfGroup(payload).then((response) => {
if (response.success) {
commit("SET_ACTIVE_SURF_GROUP", response.data);
commit("SET_FETCHING_SURF_GROUP_LOADING", false);
}
});
},
createSurfGroup: async ({ commit }, payload) => {
commit("SET_CREATING_SURF_GROUP_LOADING", true);
// Dispatches the following Surf Levels API service:
// this.$surfLevelsAPI.createNewSurfGroup(
// payload.activeSurfInstructor, payload.activeSurfSessionSelected, payload.activeGroupSurfers
// );
await Vue.prototype.$surfLevelsAPI.createNewSurfGroup(payload).then((response) => {
if (response.success) {
commit("SET_CREATING_SURF_GROUP_LOADING", false);
}
});
}
}
};

export default new Vuex.Store({
modules: {
surfGroups: surfGroups
}
});

我觉得这一切看起来都很好。

但是,在 component.Vue 内,当我 ...mapState 为:
import { mapState } from 'vuex';

export default {
name: "MyComponent",
// Computed Properties:
computed: {
...mapState('surfGroups', [
'creatingSurfGroupLoading',
]),
},
// Component Watchers:
watch: {
creatingSurfGroupLoading() {
console.log(this.creatingSurfGroupLoading);
},
},
};

我收到以下错误:
[vuex] module namespace not found in mapState(): surfGroups/
我到底做错了什么?通过阅读文档,我可以看到任何明显的差异?

最佳答案

你还没有设置命名空间。

const surfGroups = {
namespaced: true,
...

来源: https://vuex.vuejs.org/guide/modules.html#namespacing

关于vue.js - Vuex:在 mapState() 中找不到 [vuex] 模块命名空间 | mapGetters(): X/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59176722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com