【发布时间】:2020-07-06 11:51:36
【问题描述】:
我见过类似的问题。但是我失去了一些东西,无法理解为什么它在我的情况下不起作用。 我有以下 vuex 模块:
const root = {
namespaced: false,
state: {
advertisersOptions: [],
customersTypesOptions: [],
// ... more state props are here ...
},
mutations: {
setIsChoiceAllApps(state, isChoiceAllApps) {
state.isChoiceAllApps = isChoiceAllApps;
},
// and so on
},
getters: {
getErrorMessages: state => {
return state.errorMessages;
},
// and so on
},
actions: {},
};
export default root
我像这样创建我的商店:
import Vue from 'vue'
import * as Vuex from 'vuex'
import root from './modules/root'
Vue.use(Vuex);
export const store = new Vuex.Store({
modules: {
root
}
});
我将它包含在app.js 文件中:
const app = new Vue({
el: '#app',
store,
components: {
Multiselect
},
});
所以,我想在...mapState(['...']) 之后查看我的 vuex 属性。我将向您展示组件:
export default {
data() {
return {
choiceAllApplications: false
}
},
methods: {
...mapActions(['updateApplicationsAction']),
disposeAllApps: function () {
this.$store.commit("setApplications", []);
},
},
computed: {
...mapState([
"advertisersOptions",
"advertisersSelected",
// and so on are here
]),
},
如您所见,我使用namespaced: false,。我只想在全局范围内查看我的属性。但它不起作用。我将在mounted() 中创建console.log,这是转储:
如您所见,模块名称 (root) 在这里。我忘记了什么?
【问题讨论】:
标签: javascript vue.js vuex