用vue实现点击加1
点击加实现数字加1最高加到999
点击减实现数字减1最低减到1
代码如下:
html:
<div id="app">
<p>
<button @click="calc(-1)":disabled="num<=1">-</button>
<input type="text"v-model="num" @change="check()">
<button @click="calc(1)" :disabled="num>=999">+</button>
</p>
</div>
js:
<script type="text/javascript">
new Vue({
el:"#app",
data:{
num:1,
},
methods:{
calc(n){
this.num=this.num*1+n
},
check(){
if(isNaN(this.num*1)){
this.num = 1
}
if(this.num>999){this.num=999}
if(this.num<1){this.num=1}
}
}
})
</script>