index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import createPersistedState from 'vuex-persistedstate'
  4. import state from './state'
  5. import mutations from './mutations'
  6. import actions from './actions'
  7. import getters from './getters'
  8. Vue.use(Vuex)
  9. export default new Vuex.Store({
  10. state,
  11. mutations,
  12. getters,
  13. actions,
  14. plugins: [
  15. createPersistedState({
  16. storage: {
  17. // 将数据持久化到wx.storage
  18. getItem: (key) => uni.getStorageSync(key),
  19. setItem: (key, value) => uni.setStorageSync(key, value),
  20. removeItem: (key) => uni.removeStorageSync(key)
  21. },
  22. reducer: (val) => {
  23. // 只储存state中的部分数据
  24. return {
  25. systemInfo: val.systemInfo,
  26. isIphoneX: val.isIphoneX,
  27. openId: val.openId,
  28. sessionKey: val.sessionKey,
  29. unionId: val.unionId,
  30. token: val.token,
  31. userInfo: val.userInfo,
  32. pid: val.pid,
  33. channel: val.channel,
  34. adid: val.adid,
  35. clickId: val.clickId,
  36. callback: val.callback,
  37. pageConfig: val.pageConfig,
  38. closeVibrator: !!val.closeVibrator,
  39. closeAnimal: !!val.closeAnimal,
  40. hide: val.hide,
  41. shareUserId: val.shareUserId
  42. }
  43. }
  44. })
  45. ]
  46. })