1.概念
watch监听器 监听组件上的变化
watch 选项提供了一个更通用的方法,来响应数据的变化。
当需要在数据变化时执行异步或开销较大的操作时,这个方式是最有用的
{
{
msg}}
<input type="text" v-model="msg">
data(){
return{
msg:"9527",
}
},
methods:{
sendMsg(){
console.log("监听到变化后执行该方法");
}
},
watch:{
//把监听变量作为函数名称
msg(newValue,oldValue){
console.log("属性发生改变",newValue,oldValue);
console.log(this)