很简单,直接上代码,但是有个坑,formEdit.cpd这个cpd如果和rules名字不同,那么validPassWorld 重的回调value就是underfind.
<template>
<el-form-item label="确认密码" v-if="dialogType === 'add'" prop="cpd">
<el-input v-model="formEdit.cpd" type="cpd" maxlength="200" autocomplete="off"></el-input>
</el-form-item>
<template>
data() {
//失去焦距的判断两次密码不止一次的校验规则
let validPassWorld = (rule, value, callback) => {
this.pswValid = true;
if (this.formEdit.psw !== value && this.cpdValid) {
callback(new Error("两次密码输入不一致"));
return;
}
callback();
this.$refs.formEdit.clearValidate("psw");
};
return {
rules: {
cpd: [{ validator: validPassWorld, trigger: "blur" }],
}
};
}