vue.js input加减怎么实现

<div class="min " name="">-</div>

    <input class="text-box" name="pricenum" type="tel" v-model="counter" placeholder="请输入价格" onkeyup="onKeyPrice(this);" maxlength="12 " />

<div class="add" name="">+</div>




阿波罗的战车
浏览 1790回答 1
1回答

翻翻过去那场雪

<div id="app">&nbsp; &nbsp; <div class="min" name="" v-on:click="min">-</div>&nbsp; &nbsp; &nbsp; &nbsp; <input class="text-box" name="pricenum"&nbsp; type="tel" v-model="counter" placeholder="请输入价格"&nbsp; maxlength="12 " />&nbsp; &nbsp; <div class="add" name="" v-on:click="add">+</div></div>new Vue({&nbsp; &nbsp; el: '#app',&nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; &nbsp; counter: 0,&nbsp; &nbsp; },&nbsp; &nbsp; methods: {&nbsp; &nbsp; &nbsp; &nbsp; add: function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.counter = parseInt(this.counter) + 1;&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; min: function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(this.counter > 0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.counter = parseInt(this.counter) - 1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript