0
点赞
收藏
分享

微信扫一扫

Vue watch快速使用

夏侯居坤叶叔尘 2023-07-04 阅读 47

Vue watch快速使用

  • 简单监听
    watch: {
       obj(newVal, oldVal) {
          console.log(`新值:${newVal}`);
          console.log(`旧值:${oldVal}`);
      }
  }
  
  • 深度监听
    可以监听对象内的属性变化
watch: {
  obj: {
    handler(newVal, oldVal) {
      console.log(`新的值: ${newVal}`);
      console.log(`旧的值: ${oldVal}`);
    },
    immediate:true, // 进入页面就会立即执行
    deep:true
  }
}
举报

相关推荐

0 条评论