【发布时间】:2019-06-03 01:04:37
【问题描述】:
当传递的 prop 对象中的嵌套属性发生更改时,我无法更新计算属性。
this.favourite 是通过 props 传递的,但是当 this.favourite.selectedChoices.second.id 和 this.favourite 时,计算的属性不会更新。 selectedChoices.first.id 已更改。
关于如何使这个反应的任何想法?
这是计算的属性:
isDisabled() {
const hasMultipleChoices = this.favourite.choices.length
? this.favourite.choices[0].value.some(value => value.choices.length) :
false;
if (hasMultipleChoices && !this.favourite.selectedChoices.second.id) {
return true;
} else if (this.favourite.choices.length && !this.favourite.selectedChoices.first.id) {
return true;
}
return false;
}
【问题讨论】:
-
selectedChoices 是一个数组。您可能正在以 Vue 无法跟踪的方式修改其值:请参阅 vuejs.org/2016/02/06/common-gotchas/… 和 vuejs.org/v2/guide/list.html#Array-Change-Detection
标签: vue.js vuejs2 computed-properties vue-reactivity