我加入了一個清零按鈕,但是清零的時候計算屬性還是執(zhí)行并且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>
2020-04-15
不能直接這樣嗎
2019-08-08
我加了兩個變量,zero判斷是否通過input修改傳值,firstC判斷是否第一次點擊重置按鈕
watch: {
num:function(){
if(!this.zero)
{this.count++,firstC=true}
else{
this.zero = false
}
}
},
methods: {
reset:function(){
if(firstC){
this.num='';
this.zero = true;
this.count = 0;
firstC = false;
}else{
alert("點一次就行了!")
}
}
},
2019-08-07
count--應(yīng)該是最好的解決辦法了...