watch监听器
watch:{
name:{ //需要监听的属性名称
handler (newname, oldname) {
console.log(newname, oldname)
this.name = newname
},
immediate: true // 页面加载时首次执行
deep: true // 监听对象深层的数据
}
}
--------------------------
避免代码臃肿的写法
watch:{
name:{
handler: 'name'
}
immediate: true // 页面加载时首次执行
deep: true // 监听对象深层的数据
}
}
mothods:{
name(newname, oldname){
console.log(newname, oldname)
this.name = newname
}
}