element-ui 表单验证同表单一个值不能小于另一个输入值(亲测有效)
转载自:https://www.jianshu.com/p/361ebeab3a97一、效果图二、vue格式文件代码<el-row><el-col :span="6"><el-form-item label="收款金额" prop="amount" :rules="[{ required: true, message: '请输入', trigger: 'blur' }
·
转载自:https://www.jianshu.com/p/361ebeab3a97
一、效果图
二、vue格式文件代码
<el-row>
<el-col :span="6">
<el-form-item label="收款金额" prop="amount" :rules="[
{ required: true, message: '请输入', trigger: 'blur' },
{ validator: this.numberRule, trigger: 'blur'}
]">
<el-input type="number" v-model="voucherForm.amount" placeholder="收款金额"></el-input>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="核销金额">
<el-input v-model="voucherForm.writeoffAmount" disabled placeholder="核销金额"></el-input>
</el-form-item>
</el-col>
</el-row>
三、data部分代码
data() {
const numberRule = (rule, value, callback) => {
if (Number(value) >= this.voucherForm.writeoffAmount) {
if (Number.isInteger(Number(value)) && Number(value) > 0) {
callback()
} else {
callback(new Error('请输入大于零的正整数'))
}
} else {
callback(new Error('收款金额不能小于核销金额'))
}
}
return {
numberRule: numberRule,
voucherForm: {
voucher: 'R',
custName: null,
currCode: null,
writeoffAmount: null
},
}
更多推荐
已为社区贡献18条内容
所有评论(0)