user.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {
  2. getCode
  3. } from '@/api/test/index.js'
  4. export default {
  5. namespaced: true, //命名空间必须写
  6. state: {
  7. // 第一个页面参数
  8. testInfo: 'testInfotestInfotestInfotestInfo',
  9. testInfo2: '',
  10. switchs: [1, 0, 0]
  11. // 持久化常用参数
  12. // token: uni.getStorageSync('vuex').token, // token
  13. },
  14. getters: {
  15. testInfo(state) {
  16. return state.testInfo;
  17. },
  18. testInfo2(state) {
  19. return state.testInfo2;
  20. },
  21. testInfo3(state) {
  22. return state;
  23. },
  24. testInfo4(state) {
  25. return state.switchs;
  26. }
  27. },
  28. //唯一修改state值的方法
  29. // commit
  30. mutations: {
  31. testMut(state, data) {
  32. state.testInfo = data
  33. },
  34. testMut2(state, data) {
  35. state.testInfo2 = data
  36. },
  37. testMut3(state) {
  38. state.testInfo = '',
  39. state.testInfo2 = ''
  40. },
  41. testMut4(state, data) {
  42. state.switchs = data
  43. }
  44. },
  45. // 异步的操作
  46. // dispatch
  47. actions: {
  48. testAct({
  49. commit
  50. }, payload) {
  51. commit('testMut', payload)
  52. },
  53. // 登陆,持久化存储token,id
  54. testAct2(context, payload) {
  55. return new Promise(async (resolve, reject) => {
  56. getCode(payload).then(res => {
  57. const {
  58. code,
  59. msg,
  60. data
  61. } = res
  62. if (code == 0) {
  63. context.commit('testMut2', msg)
  64. resolve(res)
  65. } else {
  66. // reject(res)
  67. resolve(res)
  68. }
  69. }).catch(err => {
  70. reject(err)
  71. })
  72. })
  73. },
  74. testAct3({
  75. commit
  76. }) {
  77. console.log('jinrul-------------testAct3 ');
  78. commit('testMut3')
  79. },
  80. testAct4({
  81. commit
  82. }) {
  83. console.log('jinrul-------------testAct3 ');
  84. commit('testMut3')
  85. },
  86. },
  87. }