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

 

相关文章:

  • 2022-01-22
  • 2022-12-23
  • 2022-01-12
  • 2021-07-28
  • 2022-12-23
  • 2021-10-10
猜你喜欢
  • 2021-09-16
  • 2021-09-28
  • 2021-10-10
  • 2022-12-23
相关资源
相似解决方案