[MobX] Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify:
报错源代码展示:
async test() {
const testResult = await test()
this.testNumber = testResult
}
处理方式:
1.引入runInAction
import { runInAction } from ‘mobx’
2.在runInAction 中赋值
async test() {
const testResult = await test()
runInAction(() => {
this.testNumber = testResult
})
}
导致的原因
mobx中只能在acrion中重新赋值,异步导致赋值操作被加载到队列中,在action外面了,
runInAction 函数将赋值操作包裹在action内部.

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐