1.watch监听对象
var obj = {
‘name’:‘小明’,
‘age’:18
}
监听对象
watch:{
obj:{
deep:true,
handler:fucntion (newVal,oldVal){
console.log(newVal)
}
}
}
监听对象的属性
watch:{
obj.name:{
deep:true,
handler:function (newVal,oldVal){
console.log(newVal)
}
}
}
初次监听属性 immediate:true;
watch:{
obj.name:{
deep:true,
handler:function (newVal,oldVal){
console.log(newVal)
}
immediate:true;
}
}
computed配合watch进行监听
conputed:{
name () {
return this.obj.name
}
}
watch:{
name:(newVal.oldVal){
console.log(newVal)
}
}