You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
//observable创建被监测的对象, 对象的属性是应用对的状态, 并自动转化为显式数据
//action方法用以修改更新状态
import { observable , action } from 'mobx-miniprogram'
import { getStorage } from '../utils/storage'
export const userStore = observable ( {
//先定义响应式数据,类似变量声明
id : getStorage ( 'id' ) || '' ,
//用户信息保存
userInfo : getStorage ( 'userInfo' ) || { } ,
// 用户身份
identify : getStorage ( 'identify' ) || '' ,
//定义action
//setToken用来修改token
setId : action ( function ( id ) {
this . id = id //赋值,在方法中如果需要获取状态 可以通过this获取。
} ) ,
//对用户信息进行赋值
setUserInfo : action ( function ( userInfo ) {
this . userInfo = userInfo
} ) ,
setIdentify : action ( function ( identify ) {
this . identify = identify
} )
} )
// 计算属性 computed, 根据已有的状态产生新的状态, 必须在计算属性使用get修饰符进行修饰, 下面作为参考
// get sum(){
// //计算属性内部必须要有返回值
// return this.numA + this.numB
// }