對象屬性的watch
data() {
return {
tradeData: {
creator: 'anki',
GoodsVoList: []
}
}
},
watch: {
tradeData: {
handler(newValue, oldValue) {
console.log(newValue)
},
deep: true
}
}
- 只要tradeData中的屬性發生變化(可被監測到的),便會執行handler函數;
- 如果想監測具體的屬性變化,如GoodsVoList變化時,才執行handler函數,則可以利用計算屬性computed做中間層
對象具體屬性的watch
data() {
return {
tradeData: {
creator: 'anki',
GoodsVoList: []
}
}
},
computed: {
GoodsVoList() {
return this.tradeData.GoodsVoList
}
},
watch: {
GoodsVoList(newValue, oldValue) {
console.log(newValue)
}
}