el-input单独校验,效果图如下
<el-col :span="24">
<el-form-item label="修订次数:" prop="sPublish">
<el-input-number
v-model="addForm.sPublish"
:min="0"
:controls="false"
:precision="0"
placeholder="请输入"
@change="changesPublish"
style="width: 80px"
size="small"
/>
-
<el-input-number
v-model="addForm.ePublish"
:min="0"
:controls="false"
:precision="0"
placeholder="请输入"
style="width: 80px"
size="small"
@change="changesPublish"
/>
</el-form-item>
</el-col>
data中定义校验规则
saerchFormRules: {
sPublish: [{ validator: this.validatePass, trigger: "blur" }],
},
methods中使用
// 查询修订次数
changesPublish(val) {
this.$refs.addForm.validateField("sPublish");
},
validatePass(rule, value, callback) {
if (this.addForm.sPublish > this.addForm.ePublish) {
return callback(new Error("前数不能小于后数"));
}
},