如何在VueJS项目中构建Vuex模块?

时间:2018-05-25 19:34:12

标签: vue.js vuejs2 vue-component vuex

我已经在VueJS项目中安装了Vuex,现在我希望拥有以下结构:拥有全局"状态" (以及" getters","动作"和#34;突变")以及其他一些"模块",其中每个模块都有它拥有"州"," getters","行动"和#34;突变"。所以我不确定结构应该是什么样的。这是一个很好的方法:

enter image description here

用于"动作"," getters"的脚本。和#34;突变"我只是导出函数,这里是其他文件的内容:

根/存储/模块/ exampleModule / store.js

import * as actions from './actions';
import * as getters from './getters';
import * as mutations from './mutations';

const state = {

}

export default {        
    state,
    getters,
    actions,
    mutations
}

根/存储/ store.js:

import * as actions from './actions';
import * as getters from './getters';
import * as mutations from './mutations';

// initial state
const state = {

}

export default {        
    state,
    getters,
    actions,
    mutations
}

根/存储/ index.js:

import Vue from 'vue';
import Vuex from 'vuex';
import exampleModule from './modules/exampleModule/store.js';
import globalStore from './store';

Vue.use(Vuex);
const debug = process.env.NODE_ENV !== 'production';

export default new Vuex.Store({
  globalStore,
  modules: {
    exampleModule
  },
  strict: debug
})

0 个答案:

没有答案