index.js 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const store = new Vuex.Store({
  5. state: {
  6. userData:'',
  7. hasLogin: false
  8. },
  9. mutations: {
  10. login(state, provider) {
  11. state.hasLogin = true;
  12. state.userData = provider;
  13. //缓存用户登陆状态
  14. uni.setStorageSync('userData',provider)
  15. },
  16. logout(state) {
  17. state.hasLogin = false;
  18. state.userData = {};
  19. uni.removeStorageSync('userData')
  20. },
  21. historyUser(state, provider) {
  22. //缓存为历史登录用户
  23. uni.setStorageSync('historyUser',provider);
  24. },
  25. },
  26. actions:{
  27. setUserData:function(context,obj){
  28. context.commit('login',obj)
  29. },
  30. logout:function(context){
  31. context.commit('logout')
  32. },
  33. setHistoryUser:function(context,obj){
  34. context.commit('historyUser',obj)
  35. },
  36. }
  37. })
  38. export default store