尝试导入错误:'decorate‘不是从'mobx’导出的。我的mobx版本是6.0,我试着把包从mobx改成mobx-react,mobx-react-lite,mobx-decorate.But,但还是不能解决。
提前感谢
发布于 2020-10-20 16:27:26
decorate接口在MobX 6中已被移除,需要在目标类的构造函数中替换为makeObservable。它接受相同的参数。
示例:
import { makeObservable, observable, computed, action } from "mobx"
class Doubler {
value
constructor(value) {
makeObservable(this, {
value: observable,
double: computed,
increment: action
})
this.value = value
}
get double() {
return this.value * 2
}
increment() {
this.value++
}
}还有一个新东西makeAutoObservable,你甚至不需要使用装饰器:
import { makeAutoObservable } from "mobx"
class Timer {
// You don't even need to use decorators anymore
// property automatically becomes observable
secondsPassed = 0
constructor() {
// Call it here
makeAutoObservable(this)
}
// And this one automatically becomes an action
increaseTimer() {
this.secondsPassed += 1
}
}更多信息请点击此处:
发布于 2020-10-20 10:40:35
我一直在使用mobx,我可以导入装饰。我的mobx版本是5.9.4
https://stackoverflow.com/questions/64437377
复制相似问题