vue watch deeply monitors the changes of objects and corresponding values

1  var vm= new Vue({
 2      data:{
 3          a:1 ,
 4          b:{
 5              c:1
 6          }
 7      },
 8      watch:{
 9          a(val, oldVal){ // Ordinary watch listens to 
10              console .log("a: "+ val, oldVal);
 11          },
 12          b:{ // Deep monitoring, can monitor changes in objects and arrays 
13              deep: true ,
 14              handler: function (newVal) {
15                  console.log("bc: "+val.c, oldVal.c); // but both values ​​are printed the same 
16              },
 17          }
 18      }
 19  })
 20 vm.a=2
 21 vm.bc=2

a is an ordinary value, which will be monitored when the value of a changes, and b is an object, which cannot be written directly like a, and requires deep monitoring to capture.

Source: https://blog.csdn.net/qq_17757973/article/details/78721553

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325023891&siteId=291194637