如图我要监听items.amount,除了for循环的写法,还有什么更简单的写法吗?
1 回答

30秒到达战场
TA贡献1828条经验 获得超6个赞
computed: {
totalAmount () {
// 计算出 items 数组中的 amount 总额
return this.items.reduce((a, b) =>
({ amount: a.amount + b.amount })).amount
}
},
watch: {
totalAmount (newVal) {
// 当计算属性变更时触发更新
console.log('amount change to ', newVal)
}
}
添加回答
举报
0/150
提交
取消