四.监视reactive所定义的一个响应式中的某一个属性 person.age
watch(()=>person.age,(newValue,oldValue)=>{
console.log('person.age变化了',newValue,oldValue)
})
得写成一个函数 感觉好麻烦
----------------------------------------------
五.监视reactive所定义的一个响应式中的某一些属性 person.age person.name
watch ( [ ()=>person.age , ()=>person.name ],(newValue,oldValue)=>{
console.log('age/name变化了',newValue,oldValue)
})
----------------------------------------------
特殊情况
监视reactive所定义的中的响应式数据中的一个属性 比如person.job但是job不是最终数据 是一个对象 就是下边还封装了数据 job:{xinzi:xxx;}
watch(()=>person.job,(newValue,oldValue)=>{
console.log('person.job变化了',newValue,oldValue)
} , {deep:true}) //此时deep配置有效