vue中watch基本用法: 

new Vue({
            el: '#t1',
            data: {
                a: {
                    b: 1,
                    c: 2
                },
            },
            methods: {
                ch() {
           this.a.d=5     //不打印ok 原理是watch只watch挂在data中的数据,初始化时给他们分别赋予setter与getter,如果是中途加上的属性,由于没有setter与getter,不会被watch到。
           this.a.c=5    //打印ok ,测试时与上面代码只写一个。 } },
watch: {           a:{
            handler(){
              console.log('ok')
            },
            deep:true
          } },
)}
//html:
<div class='t1' id='t1'>
  <button @click='ch'>+++</button>
</div>
 

 

})

相关文章:

  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
  • 2021-11-08
  • 2021-12-22
  • 2022-02-16
  • 2022-01-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-29
  • 2021-12-31
  • 2021-07-25
  • 2022-02-22
  • 2021-09-08
  • 2022-12-23
相关资源
相似解决方案