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) //这里面可以执行一旦监听的值发生变化你想做的操作 } }