[mobx] 登录状态维护相关 action reaction 报错问题 烦请各位高人看一下 magic 发布于 2019-09-24 1815 次阅读
configure ({
enforceActions : ' always '
})
......
@ action . bound
setToken ( value ) {
this . token = value
}
@ action . bound
setUserInfo ( value ) {
this . userInfo = value
}
@ action . bound
setAccountStatus ( value ) {
this . account_status = value
}
@ action . bound
async doWeappLogin ( body ) {
this . toggleLoading ( true )
try {
const resp = await miniAppLogin ( body )
if ( resp ) {
const { token , needBind } = resp
this . setToken ( token )
const userInfo = await getUserInfo ()
this . setUserInfo ( userInfo )
this . setAccountStatus ( true )
return
}
} catch ( e ) {
console . log ( e )
}
}
Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an
actionif this change is intended.
## 尝试办法
将 enforceActions 变成 observe nerver 依然报错
javascript
// 用runInAction包裹依然报错
const _this = this
runInAction(async() : {
_this.setToken(token)
const userInfo = await getUserInfo()
_this.setUserInfo(userInfo)
_this.setAccountStatus(true)
})
## 期待的结果
消除报错, mobx 一报错就会阻止视图渲染, 但是值确实是改过来了
本站文章均为原创内容,如需转载请注明出处,谢谢。
统计信息
学员: 29339
视频数量: 1985
文章数量: 489
© 汕尾市求知科技有限公司
| Rails365 Gitlab
| Qiuzhi99 Gitlab
| 知乎
| b 站
| 搜索
粤公网安备 44152102000088号
| 粤ICP备19038915号
Top
兄弟,能借你账号用一下吗?谢啦!