index.js 798 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const store = new Vuex.Store({
  5. state: {
  6. hasLogin: false,
  7. token:'',
  8. userInfo: {},
  9. },
  10. mutations: {
  11. setLogin(state, userInfo) {
  12. state.userInfo = userInfo || {}
  13. state.token = userInfo.accessToken
  14. state.tokenhead = userInfo.tokenhead
  15. state.hasLogin = Boolean(state.token)
  16. uni.setStorage({
  17. key: "userInfo",
  18. data: userInfo.data
  19. })
  20. uni.setStorage({
  21. key: "hasLogin",
  22. data: true
  23. })
  24. uni.setStorage({
  25. key: "token",
  26. data: userInfo.accessToken
  27. });
  28. uni.setStorage({
  29. key: "tokenhead",
  30. data: userInfo.tokenhead
  31. });
  32. },
  33. logout(state) {
  34. userInfo = {}
  35. hasLogin: false,
  36. uni.removeStorage({
  37. key: "userInfo"
  38. })
  39. }
  40. },
  41. actions: {
  42. }
  43. })
  44. export default store