From 405ef9e2b3e61bd6195b58996504b9cb3939ef6f Mon Sep 17 00:00:00 2001 From: bowen <54492610+jiaowoxiaobala@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:54:09 +0800 Subject: [PATCH] fix: async validator (#3194) --- src/views/demo/form/RuleForm.vue | 4 +++- src/views/demo/system/account/account.data.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/views/demo/form/RuleForm.vue b/src/views/demo/form/RuleForm.vue index 183c0471e..b4f290c12 100644 --- a/src/views/demo/form/RuleForm.vue +++ b/src/views/demo/form/RuleForm.vue @@ -192,10 +192,12 @@ message: '请输入数据', }, { + trigger: 'blur', validator(_, value) { return new Promise((resolve, reject) => { + if (!value) return resolve(); isAccountExist(value) - .then(() => resolve()) + .then(resolve) .catch((err) => { reject(err.message || '验证失败'); }); diff --git a/src/views/demo/system/account/account.data.ts b/src/views/demo/system/account/account.data.ts index a30c685a0..18dd12e62 100644 --- a/src/views/demo/system/account/account.data.ts +++ b/src/views/demo/system/account/account.data.ts @@ -89,10 +89,12 @@ export const accountFormSchema: FormSchema[] = [ message: '请输入用户名', }, { + trigger: 'blur', validator(_, value) { return new Promise((resolve, reject) => { + if (!value) return resolve(); isAccountExist(value) - .then(() => resolve()) + .then(resolve) .catch((err) => { reject(err.message || '验证失败'); });