vue中使用watch监视对象中的属性的方法

单层监控直接写该变量的方法,但是深度监控


watch:{
//方式一:监控vue实例的数据
age:(newValue,oldValue) => {
console.log('name的newValue值为:'+newValue+',旧值为:'+oldValue);
},
user:{
handler:(newValue,oldValue) => {
console.log('age的newValue值为:'+newValue.age+',旧值为:'+oldValue.age);
//原来的旧值已经看不见了,只能看到新的值
},
deep: true //深度监视,当对象中的属性发生变化时会被监控
}
}

猜你喜欢

转载自blog.csdn.net/liukai6/article/details/80917677
今日推荐