【发布时间】:2020-03-11 23:11:56
【问题描述】:
我在 Nuxt 中创建了一个这样的 vuex 商店。
export const state = () => ({
id: "",
type: null,
name: null,
});
export const mutations = {
setProfile(state, profile) {
state.id = profile.idStr;
state.type = profile.type;
state.name = profile.name;
}
};
export const getters = {
name(state) {
return state.name;
}
};
数据以store.commit("profile/setProfile", profile.data);存储并成功设置。 (值显示在 chrome dev-tools 中)
现在我正在尝试使用这样的mapGetters 方法访问我的一个组件中的属性name。
import { mapGetters } from "vuex";
export default {
computed: mapGetters({
name: "profile/name"
})
};
我的问题是找不到getter。
ERROR [vuex] unknown getter: profile/name
这种方法有什么问题?
【问题讨论】:
-
你能给
setProfile一个有效载荷的例子吗?您的商店是否在profile.js文件中? -
我已经添加了示例。存储文件名为
profile.js -
您发现问题了吗?
标签: javascript vuex nuxt.js