用if判断小于0的直接设为0
<el-input type="number" v-model="data" :min="0" oninput="if(value<0)value=0" placeholder="if判断" />
通过正则限制只能输入数字或小数点
<el-input type="number" v-model="data" oninput="value=value.replace(/[^0-9.]/g,'')" placeholder="正则" />
uniapp
<input type="number" maxlength="5" @input="checkPrice" class="inputtt" v-model="indata.count" placeholder="请输入兑换数量" />
checkPrice(e) {
let that = this;
let num = e.detail.value
if (num > 10000) {
this.indata.count = 10000;
uni.showToast({
title: '最大可兑换10000',
icon: 'none',
duration: 1500
});
} else if (num < 0) {
this.indata.count = 0;
uni.showToast({
title: '请输入正确的数量',
icon: 'none',
duration: 1500
});
}
},