Javascript Vuex存储区中的NuxtJS值未定义
我在Nuxt中创建了这样一个vuex商店Javascript Vuex存储区中的NuxtJS值未定义,javascript,vuex,nuxt.js,Javascript,Vuex,Nuxt.js,我在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 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开发工具中)
现在,我正在尝试使用mapGetters
方法访问我的一个组件中的属性name
import { mapGetters } from "vuex";
export default {
computed: mapGetters({
name: "profile/name"
})
};
我的问题是找不到getter
ERROR [vuex] unknown getter: profile/name
这种方法有什么问题?是否需要使用mapGetters
而不是mapState
到目前为止(nuxt v2.14.7),语法是
export default {
computed: {
...mapGetters({getName: 'profile/name'}),
}
}
然后在组件中,getter可以用作
this.getName;
您能给出一个示例有效负载到setProfile
?你的商店在profile.js
文件中吗?我已经添加了这个例子。商店文件名为profile.js
您解决问题了吗?谢谢。我想我们走对了。现在我得到了错误[vuex]未知getter:profile/name
恐怕我暂时帮不上忙了对不起!必须睡觉,没问题。无论如何谢谢你