index.js 703 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import {
  4. getUserInfo
  5. } from '../api';
  6. Vue.use(Vuex);
  7. const store = new Vuex.Store({
  8. state: {
  9. userInfo: uni.getStorageSync('userInfo'),
  10. userId: uni.getStorageSync('userId'),
  11. isLogin: uni.getStorageSync('isLogin'),
  12. },
  13. mutations: {
  14. changeIsLogin(state, bol) {
  15. state.isLogin = bol;
  16. },
  17. changeUserInfo(state, value) {
  18. state.userInfo = value;
  19. },
  20. changeUserId(state, value) {
  21. state.userId = value;
  22. },
  23. },
  24. actions: {
  25. resetUserInfo({
  26. commit
  27. }) {
  28. return getUserInfo().then((res) => {
  29. const {user} = res.data;
  30. commit('changeUserInfo', user);
  31. return Promise.resolve(user);
  32. })
  33. },
  34. }
  35. })
  36. export default store;