user.js 1.3 KB

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