我正在使用计算检查何时某些信息已更改。
当我单击并计算运行时,我既可以看到数据中的新值,也可以看到分配给计算函数的旧值。可通过Chrome Vue开发工具查看此值。
我想做的是访问计算出的数据,而不是返回。那是先前正确的数据,但是计算得出的数据更新了内部的收益。
我要执行此操作的原因是为了显示数据不再匹配,并且某些更改。
selectedLenses: "30626146713652" <-- Data
changeSelectedLenses: "28717846790196" <-- Computed
单击运行计算函数的按钮,它将更改为:
selectedLenses: "28717846790196" <-- Data
changeSelectedLenses: "30626146713652" <-- Computed (Want to access this data saved to the computed function)
如果您想观察变化,则watch
可能会使用。它处理上一个和下一个值,您可以分配它来观看计算出的...
new Vue({
//...
data() {
return {
selectedLenses: 0
};
},
computed: {
changeSelectedLenses() {
return this.selectedLenses + 2;
}
},
watch: {
changeSelectedLenses(newValue, oldValue) {
alert(`changeSelectedLenses computed property changed from ${oldValue} to ${newValue}`);
}
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句