废话不多说,直接上代码对比
变量与对象用watch监听的区别
<script>
export default {
name: 'home',
data() {
return {
name:"",
user:{
name:"张三"
}
};
},
mounted() {
},
computed:{
},
methods: {
},
watch:{
//监听变量
name(newValue,oldValue){
console.log("更新前:"+oldValue+",更新后:"+newValue);
},
//监听对象
user:{
handler:function(newValue,oldValue{
console.log("更新前:"+oldValue.name+",更新后:"+newValue.name);
},
deep:true
}
}
};
</script>