猿问
vue监听data中的某一数组的某一项
如图我要监听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) }}
0
0
0
随时随地看视频
慕课网APP
相关分类
JavaScript
我要回答