Watch method
vm.$watch('a'.function(newValue, oldValue) {// This callback will be called after 'vm.a' changes)}Copy the code
Chestnut:
var data={a :1};
var vm=new Vue({
el:'#app', data:data }); // This callback will call vm after 'vm.a' changes.$watch('a'.function (newValue, oldValue) {
console.log(newValue, oldValue);
})
vm.a=2;
Copy the code
Used to compare the value of a variable before and after a change. Use it before the value changes.