为什么调用 updates 方法,不能实时更新 data 内的数据(19行),而是需要加上 setTimeout 才可以实时更新(21行)
index.js
updates() {
this.update()
console.log("update => 19", this.data.global)
setTimeout(() => {
console.log("update => 21", this.data.global)
}, 10);
}
global.js
import { observable, action } from "mobx-miniprogram";
const numc = 0;
export const global = observable({
numA: 1,
numB: 2,
numC: numc,
get sum() {
return this.numA + this.numB;
},
update: action(function () {
const sum = this.sum;
this.numA = this.numB;
this.numB = sum;
}),
});
已解决
updates() { this.update(); this.updateStoreBindings(); }