Vue侦听器
作者:互联网
侦听器可以检测组件的点击次数
<template>
<div>
<h1 :style="styleObj">点击次数:{{num}}</h1>
<button @click="addClick">点击</button>
</div>
</template>
<script>
export default{
name:'App',
data:function(){
return{
num:0
}
},
methods:{
addClick:function(){
this.num ++;
}
},
watch:{ //监听器函数
num:function(newValue,oldValue){
console.log(newValue);
console.log(oldValue);
if(newValue>10){
console.log("值大于10");
this.styleObj = {
backgroundColor:"red"
}
}
}
}
}
</script>
标签:function,Vue,console,log,侦听器,点击,num,newValue 来源: https://blog.csdn.net/sinat_33940108/article/details/112468339