问题描述
我有类似这样的 MobX 商店,并想使用库 mobx-persist
https://github.com/pinqy520/mobx-persist 为其添加状态持久性
但我不知道该怎么做
我的商店:
import { observable,makeObservable,action,runInAction } from 'mobx'
import Api from './Api'
export function userStore() {
return makeObservable({
isAuthenticated: false,token: '',async login() {
const api = new Api()
let tokenStr = await api.getToken(encodeURIComponent('xxx'),encodeURIComponent('yyy'))
runInAction(() => {
this.token = tokenStr
})
this.setAuthenticated(this.token)
},setAuthenticated(tokenValue) {
this.isAuthenticated = tokenValue != '' ? true : false
}
},{
isAuthenticated: observable,token: observable,login: action.bound,setAuthenticated: action.bound
})
}
我想保留两个字段:
- 已认证
- 令牌
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)