index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { createStore, createLogger } from 'vuex';
  2. import weather from './modules/weather';
  3. import user from './modules/user';
  4. const debug = process.env.NODE_ENV !== 'production';
  5. // 默认状态
  6. const state = {
  7. websocketTimeSec: 5000,
  8. loading: false, //全局 - 加载中....
  9. themeName: "light", // 主题
  10. windturbineMap: {},
  11. };
  12. //改变状态的方法
  13. const mutations = {
  14. loadingStore(state, tag) {
  15. state.loading = tag;
  16. },
  17. changeTheme(state, tag) {
  18. state.themeName = tag;
  19. },
  20. update(state, newData) {
  21. state.windturbineMap = newData.data
  22. }
  23. };
  24. const actions = {
  25. getupdate(context, newData) {
  26. context.commit("update", newData);
  27. },
  28. };
  29. const getters = {
  30. authToken: state => state.user.authToken, //建立token的快捷访问 user 是因为index.js中导入的时候名称定义为user
  31. submitDDTag: state => state.submitDDTag,
  32. loading: state => state.loading,
  33. username: state => state.user.username,
  34. themeName: state => state.themeName,
  35. asidez: state => state.z,
  36. mainy: state => state.y,
  37. login: state => state.login
  38. }
  39. export default createStore({
  40. modules: {
  41. weather,
  42. user
  43. },
  44. state,
  45. mutations,
  46. actions,
  47. getters,
  48. strict: debug,
  49. plugins: debug ? [createLogger()] : []
  50. });