慕虎3255728
2019-08-06 15:05
<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>
不能直接这样吗
<button type="reset" value="重置按钮"></button>
我加了两个变量,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("点一次就行了!")
}
}
},
count--应该是最好的解决办法了...
vue2.5入门
146825 学习 · 657 问题
相似问题