1.監聽對象需要深度監聽 ,如下代碼可以監聽整個msg對象的變化
watch: { msg: { handler(newValue, oldValue) { console.log(newValue) }, deep: true } }
2.監聽對象里面某個屬性的變化,通過computed做中間層實現
computed: { channel() { return this.msg.channel } }, watch:{ channel(newValue, oldValue) { console.log('new: %s, old: %s', newval, oldVal) //這里面可以執行一旦監聽的值發生變化你想做的操作 } }