vue 监听data中数据变化

 

<script>
export default {
  data(){
    return {
      items:[]
    }
  },
  watch: {
    items: {
      handler(newValue,oldValue) {
        //newValue 改变后的数据
        //oldValue  改变前的数据
      }
      //,deep: true
    }
  }
}
</script>

如果监听对象内部属性改变需要增加deep: true

下面是简写形式 想要监听对象内部属性改变不能使用简写形式

watch: {
    items(newVal, oldVal){
    }
}

 

posted @ 2020-07-30 17:56  荣超  阅读(3878)  评论(0编辑  收藏  举报