vue监听data中的某一数组的某一项

https://img1.mukewang.com/5c1472b000010cfc03460531.jpg

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

心有法竹
浏览 2634回答 1
1回答

30秒到达战场

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)  }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript