1.下载vue
2.引入封装
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'Vue.use(Vuex)const modulesFiles = require.context('./modules', true, /\.js$/)const modules = modulesFiles.keys().reduce((modules, modulePath) => {// set './app.js' => 'app'const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')const value = modulesFiles(modulePath)modules[moduleName] = value.defaultreturn modules
}, {})const store = new Vuex.Store({modules,getters
})export default store
3.挂载在main.js
方式一:异步方法actions内提交异步
methods: {setBaseData() {if (this.userInfo.schoolId) this.$store.dispatch('base/queBaseData', this.userInfo)}}
2.调用异步存值
方式二:commit同步存值