import { createStore, createLogger } from 'vuex'; import weather from './modules/weather'; import user from './modules/user'; const debug = process.env.NODE_ENV !== 'production'; // 默认状态 const state = { websocketTimeSec: 5000, loading: false, //全局 - 加载中.... themeName: "light", // 主题 windturbineMap: {}, }; //改变状态的方法 const mutations = { loadingStore(state, tag) { state.loading = tag; }, changeTheme(state, tag) { state.themeName = tag; }, update(state, newData) { state.windturbineMap = newData.data } }; const actions = { getupdate(context, newData) { context.commit("update", newData); }, }; const getters = { authToken: state => state.user.authToken, //建立token的快捷访问 user 是因为index.js中导入的时候名称定义为user submitDDTag: state => state.submitDDTag, loading: state => state.loading, username: state => state.user.username, themeName: state => state.themeName, asidez: state => state.z, mainy: state => state.y, login: state => state.login } export default createStore({ modules: { weather, user }, state, mutations, actions, getters, strict: debug, plugins: debug ? [createLogger()] : [] });