index.js 881 B

1234567891011121314151617181920212223242526272829303132
  1. import {
  2. observable,
  3. action
  4. } from "mobx-miniprogram";
  5. // observable: 用于创建 store 的实例对象
  6. // action: 用于包裹修改 store 数据的函数
  7. export const store = observable({
  8. token_val: wx.getStorageSync("hw_token"),
  9. phone_val: wx.getStorageSync("hw_mobile"),
  10. // 计算属性
  11. get token() {
  12. return this.token_val;
  13. },
  14. get phone() {
  15. return this.phone_val;
  16. },
  17. setStore: action(function (val) {
  18. wx.setStorageSync("hw_token", val);
  19. this.token_val = wx.getStorageSync("hw_token");
  20. }),
  21. storeSetPhone: action(function (val) {
  22. wx.setStorageSync("hw_mobile", val);
  23. this.phone_val = wx.getStorageSync("hw_mobile");
  24. }),
  25. setStore: action(function (tval, mval) {
  26. wx.setStorageSync("hw_token", tval|| "");
  27. wx.setStorageSync("hw_mobile", mval|| "");
  28. this.token_val = tval|| '';
  29. this.phone_val = mval|| "";
  30. })
  31. })