1234567891011121314151617181920212223242526272829303132 |
- import {
- observable,
- action
- } from "mobx-miniprogram";
- // observable: 用于创建 store 的实例对象
- // action: 用于包裹修改 store 数据的函数
- export const store = observable({
- token_val: wx.getStorageSync("hw_token"),
- phone_val: wx.getStorageSync("hw_mobile"),
- // 计算属性
- get token() {
- return this.token_val;
- },
- get phone() {
- return this.phone_val;
- },
- setStore: action(function (val) {
- wx.setStorageSync("hw_token", val);
- this.token_val = wx.getStorageSync("hw_token");
- }),
- storeSetPhone: action(function (val) {
- wx.setStorageSync("hw_mobile", val);
- this.phone_val = wx.getStorageSync("hw_mobile");
- }),
- setStore: action(function (tval, mval) {
- wx.setStorageSync("hw_token", tval|| "");
- wx.setStorageSync("hw_mobile", mval|| "");
- this.token_val = tval|| '';
- this.phone_val = mval|| "";
- })
- })
|