我的模型如下:
export default {
data() {
return {
...
salesOrder: {
...
line_items: [{
status: 'saved',
item_number: 1,
description: 'The first line item'
cost: 458.00,
quantity: 2
}, {
status: 'saved',
item_number: 2,
description: 'The second line item'
cost: 0.589,
quantity: 3
}]
}
}
}
}
每当status
,description
或quantity
字段在同一订单项上发生更改时,我都希望更新cost
字段,以使我的UI看起来像这样:
问题是,看起来没有任何方法可以监视数组内对象的属性。
我可以为该数组创建一个计算属性,然后观察它,但是随后我得到整个数组作为val
和newVal
参数:
{
computed: {
lineItems() {
return this.salesOrder.line_items;
}
},
watch: {
lineItems() {
handler(val, newVal) {
// val and newVal are the whole array
},
deep: true
}
}
}
有什么建议吗?预先感谢您的帮助。