1. Al llamar a watch durante la inicialización de la página, debe agregar el atributo inmediato
export default{
data(){
return{
name:'id'
}
},
watch:{
name:{
immediate:true,
handler:function(newVal){
console.log(newVal)
}
}
}
}
2. Cuando los datos son un objeto, debe agregar el atributo profundo para un monitoreo profundo.
export default{
data(){
return{
information:{
name:'cl',
age:'25'
}
}
},
watch:{
information:{
deep:true,
handler:function(newVal){
console.log(newVal)
}
}
}
}
3. Cuando los datos son un objeto, monitoree los cambios en un determinado atributo del objeto.
export default{
data(){
return{
information:{
name:'cl',
age:'25'
}
}
},
watch:{
'information.age':{
deep:true,
handler:function(newVal){
console.log(newVal)
}
}
}
}