完整的代码, 可以复制引用
vue2的vuex配置
import Vue from 'vue'
import Vuex from 'vuex'
// 导入API库
import Api from '../lib/api/api'
// 导入工具库
import Utils from '../lib/utils/utils'
// 使用Vuex插件
Vue.use(Vuex);
// 定义Vuex存储
let store = new Vuex.Store({
state: {
// 平台名称
platformName: ''
},
mutations: {
// 网站基本配置信息
baseConfig(state, data) {
state.baseConfig = data;
},
},
actions: {
// 获取网站基本信息
baseConfig({state, commit }) {
// 请取消注释以下代码以从API获取基本配置
// Api.baseConfig().then( response => {
// if (response['success']) {
// commit('baseConfig', response.data);
// }
// })
},
}
});
// 导出存储以供其他部分使用
export default store;