el-form表单项唯一
<el-form-item
label="项目名称"
prop="programName"
v-if="crud.status.title.indexOf('新增') != -1"
>
<el-input v-model="form.programName" style="width: 300px" />
</el-form-item>
rule里定义
programName: [
{ required: true, message: "项目名称不能为空", trigger: "blur" },
{ validator: validateProgramName, trigger: "blur" },
],
//data里定义
data(){
var validateProgramName = (rule, value, callback) => {
if (this.program.indexOf(value) != -1) {
// console.log(true);
callback(new Error("项目名称已存在"));
} else {
// console.log(false);
callback();
}
};}
// 在methods里加: CRUD.HOOK.beforeToAdd钩子
[CRUD.HOOK.beforeToAdd]() {
for (var i = 0; i < this.crud.data.length; i++) {
this.program.push(this.crud.data[i].programName);
}
},