我加入了一个清零按钮,但是清零的时候计算属性还是执行并且count+1了,只能在再加一个count--才能解决
<div id="root">
姓:<input v-model="firstName" />
名:<input v-model="lastName" />
<div>{{fullName}}</div>
<div>{{count}}</div>
<button @click="firstName='',lastName='',count =0 ,count --" v-model="clear">清除</button>
</div>
<script>
new Vue({
el:"#root",
data:{
firstName:'',
lastName:'',
count:0 ,
clear:''
},
computed:{
fullName: function(){
return this.firstName+' '+this.lastName
}
},
watch:{
fullName:function(){
this.count ++
},
},
})
</script>