store 初始化数据
index.js
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
import getters from './getters';
const modulesFiles = require.context('./modules', true, /\.js$/);
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1');
const value = modulesFiles(modulePath);
modules[moduleName] = value.default;
return modules;
}, {});
const store = new Vuex.Store({
modules,
getters,
});
export default store;
getter.js
const getters = {
msg: (state) => state.appstore.msg,
};
export default getters;
modules-pushSheet.js
const state = {
businessCode: [false, false, true],
businessData: null,
productData: null,
};
const mutations = {
editBusinessCode(state, payload) {
state.businessCode[payload.index] = payload.flag;
console.log(state.businessCode, 'state.businessCode');
},
editBusinessData(state, payload) {
state.businessData = payload;
console.log(state.businessData, 'state.businessData');
},
editProductData(state, payload) {
state.productData = payload;
console.log(state.productData, 'state.productData');
},
};
const actions = {
};
export default { namespaced: true, state, mutations, actions };
页面 存数据
created() {
let query = new getQueryString();
console.log(query, 'query');
if (query.businessId) {
this.$store.commit('pushSheet/editBusinessCode', 1);
this.queryBizId = query.businessId;
this.getBizDetail(query.businessId);
this.getAreaList();
}
},
页面 取数据
const businessCode = this.$store.state.pushSheet.businessCode;