iview中input进行数字验证
1.html中如下
<FormItem label="折扣力度【提示:输入1表示当前商品1折促销】" prop="rate" label-position="top" class="discount_item">
<!-- <InputNumber :min="1" :max="9.9" v-model="formData.rate" placeholder="请输入折扣力度"></InputNumber> -->
<Input number clearable v-model="formData.rate" placeholder="请输入折扣力度" />
</FormItem>
2.data中如下
data() {
const validateRate = (rule, vaule, callback) => {
if(value % 1 != 0) {
callback(new Error('请输入整数'))
} else{
callback();
}
}
return {
// 验证
ruleValidate: {
rate: [
{ required: true, type:'number', message: "请输入折扣力度", trigger: "blur" },
{type: 'number', message: '请输入整数', trigger: 'blulr', transform(value) {
return Number(value)
}, validator: validateRate}
],
},
}
}
网友评论