data(){var checkSno = (rule, value, callback) => {if (!value) {callback(new Error("请输入账号"));} else if (value.length > 20) {callback(new Error("长度为1-20"));} else {if (this.form.id) {// 修改时检查账号是否重复selectLoginId({ sno: value, id: this.form.id }).then((res) => {if (res) {callback();} else {callback(new Error("账号重复,请选择其他账号"));}}).catch((error) => {callback(new Error("验证失败,请重试"));});} else {// 新增时检查账号是否重复selectLoginId({ sno: value }).then((res) => {if (res) {callback();} else {callback(new Error("账号重复,请选择其他账号"));}}).catch((error) => {callback(new Error("验证失败,请重试"));});}}};return{rules: {sno: [{ validator: checkSno, trigger: "blur" }],}}
}
html代码:
<el-form-itemlabel="账号":label-width="formLabelWidth"requiredprop="sno"><el-input v-model="form.sno" autocomplete="off"></el-input></el-form-item>