由于启用了严格模式,因此不允许在不使用操作的情况下更改(观察到的)可观察值.尝试修改:OrderLine@1.price


class OrderLine {
price = 0
amount = 1
stop = () => { }
constructor(price: number) {
makeObservable(this, {
price: observable,
amount: observable,
total: computed
})
this.stop = autorun(() => {
console.log("Total: " + this.total)
})
this.price = price
}
get total() {
console.log("Computing...")
return this.price * this.amount
}
}
export default new OrderLine(0)

我收到警告

由于启用了严格模式,因此不允许在不使用操作的情况下更改(观察到的(可观察值。尝试修改:OrderLine@1.price

问题出在哪里?

mobx文档******

class OrderLine {
price = 0
amount = 1
stop = () => { }
constructor(price: number) {
this.price = price
makeObservable(this, {
price: observable,
amount: observable,
total: computed
})
this.stop = autorun(() => {
console.log("Total: " + this.total)
})
}
get total() {
console.log("Computing...")
return this.price * this.amount
}
}
export default new OrderLine(0)

makeObservable之前的this.price = price

相关内容

最新更新