首页React
magic · 大罗巅峰

[mobx] 登录状态维护相关 action reaction 报错问题 烦请各位高人看一下

magic发布于

代码

  • 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 anactionif 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一报错就会阻止视图渲染, 但是值确实是改过来了

本站帖子均为原创内容,如需转载请注明出处,谢谢。

1 条回复
喜欢

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 在线学员:87

Top