The computed property in Mobx cannot be triggered.

1. Using computed in mobx does not work

class ODOM {
  constructor(props) {
    console.log("how many times")
  }
  @observable speed = 0
  @action change(obj) {
    console.log(obj)
    Object.keys(obj).forEach(item => {
      this[item] = obj[item]
    })
  }
  @computed get velocity() {
    console.log("entry")
    return this.speed*60*60/1000
  }
}
const model = new ODOM()
let total = 0
setInterval(() => {
  model.change({
    speed: PPtotal
  })
}, 3000)
export default model
The console in

2.computed is triggered only once
3. Do not see what is wrong with the code, solve

Mar.13,2021
It has been solved in

stackoverflow. address

Menu