Vue.js computed property not updating

前端 未结 7 723
猫巷女王i
猫巷女王i 2020-12-29 22:36

I\'m using a Vue.js computed property but am running into an issue: The computed method IS being called at the correct times, but the value returned by the computed

7条回答
  •  囚心锁ツ
    2020-12-29 22:47

    If your intention is for the computed property to update when project.classes.someSubProperty changes, that sub-property has to exist when the computed property is defined. Vue cannot detect property addition or deletion, only changes to existing properties.

    This has bitten me when using a Vuex store with en empty state object. My subsequent changes to the state would not result in computed properties that depend on it being re-evaluated. Adding explicit keys with null values to the Veux state solved that problem.

    I'm not sure whether explicit keys are feasible in your case but it might help explain why the computed property goes stale.

    Vue reactiviy docs, for more info: https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats

提交回复
热议问题