vuejs怎么watch對象里某個屬性的變化
3 回答

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
用計算屬性,返回值是這個列表值相加
computed: { countTotal: function () { let total = 0; this.items.forEach(function (item) { total += item.count }) return total } }
監聽用 watch選項
watch: { items: { handler: function () {}, deep: true } }
對象要深復制,默認是淺復制

慕的地10843
TA貢獻1785條經驗 獲得超8個贊
<pre t="code" l="js">new Vue({
data: {
name: 'sigma'
},
watch:{
name: function( val ){
console.log( 'name has been changed:', val );
}
}
})
添加回答
舉報
0/150
提交
取消