index.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. // import user from './modules/user.js'
  4. Vue.use(Vuex)
  5. const store = new Vuex.Store({
  6. // state 中存放的就是全局共享的数据
  7. state: {
  8. user: {
  9. appid: 'wxd3bab568bc42d1de',
  10. token: '',
  11. code: '123',
  12. name: '用户',
  13. phone: '',
  14. personId: '',
  15. classId: '',
  16. sexNumber: null,
  17. Semester: '',
  18. sex: '',
  19. termId: '',
  20. Classs: ''
  21. }
  22. },
  23. // Mutation 用户变更Store数据
  24. mutations: {
  25. SET_USER_INFO (state, value) {
  26. state.user = {
  27. ...state.user,
  28. ...value
  29. }
  30. console.log('SET_USER_INFO被修改为:', state.user);
  31. },
  32. },
  33. //Getter用于对Store中的数据进行加工处理,形成新的数据
  34. getters: {
  35. completedUserInfo (state) {
  36. return state.user
  37. }
  38. },
  39. //Action 是专门用于处理异步任务的
  40. actions: {
  41. getUserInfo ({ dispatch, commit }, value) {
  42. console.log('actions---vaule', value);
  43. //处理异步还得调用mutations里面的方法修改数据 mutations 不能处理异步
  44. commit('SET_USER_INFO', value)
  45. dispatch('SET_USER_INFO', value)
  46. }
  47. }
  48. });
  49. export default store;