【发布时间】:2018-09-15 15:05:06
【问题描述】:
我有以下模块:
export const ProfileData = {
state: {
ajaxData: null;
},
getters: {/*getters here*/},
mutations: {/*mutations here*/},
actions: {/*actions here*/}
}
并且此模块已在我的全球商店中注册:
import {ProfileData} from './store/modules/ProfileData.es6'
const store = new Vuex.Store({
modules: {
ProfileData: ProfileData
}
});
我也使用了Vue.use(Vuex),并将商店设置在new Vue({ store: store})。但是,当我尝试通过this.$store.ProfileData.ajaxData 在我的一个组件中访问属于ProfileData 模块的ajaxData 时,控制台显示undefined 错误。阅读this.$store.ProfileData 或this.$store.ajaxData 也是如此,而this.$store 已定义并且我已经能够阅读它。我还看到ProfileData 对象添加到浏览器控制台中商店的_modules 属性中。
访问注册到Vuex 的模块我做错了什么?我怎样才能访问这些?
【问题讨论】:
标签: vue.js vuejs2 vue-component vuex vuex-modules