vue中,如何监听一个对象内部的变化
watch:{
obj:{
handler(newValue,oldValue){
console.log("obj changed")
},
deep: true,//深度遍历
immediate: true
//默认第一次绑定的时候不会触发watch监听,值为true时可以在最初绑定的时候执行
}
}
方法② :指定key
watch: {
"dataobj.name": {
handler(newValue, oldValue) {
console.log("obj changed");
}
}
}
方法③:computed
computed(){
ar(){
return this.obj.name
}
}