.vue文件中监听input的输入值变化事件
改变input的值,就调用一个事件,第一想到的是oninput
<template>
<div class="m_number">
<span class="reduce" v-on:click="changeNum('reduce')">-</span>
<input type="number" v-on:input="changeNum('input')" v-model="buyNum">
<span class="add" v-on:click="changeNum('add')">+</span>
</div>
</template>
<script>
export default{
data(){
return {
buyNum:'',
increment:'1
}
},
methods:{
changeNum(type){
let num = this.bugNum;
if(type=='add'){
num = num + increment;
};
if(type=='reduce'){
num = num - increment;
};
this.buyNum = num;
console.log(this.buyNum);
}
}
}
</script>