From db32ef962140333a13e2a04ba4642e7423bc4bef Mon Sep 17 00:00:00 2001 From: Moonofweisheng <1780903673@qq.com> Date: Mon, 4 Nov 2024 12:59:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Form=20=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E8=A7=84=E5=88=99validator=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5?= =?UTF-8?q?Error=E4=BD=9C=E4=B8=BA=E6=A0=A1=E9=AA=8C=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #667 --- src/pages/form/Index.vue | 2 +- .../wot-design-uni/components/wd-form/wd-form.vue | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/form/Index.vue b/src/pages/form/Index.vue index e2b88c69..fa18a634 100644 --- a/src/pages/form/Index.vue +++ b/src/pages/form/Index.vue @@ -149,7 +149,7 @@ const validator = (val: any) => { if (String(val).length >= 4) { return Promise.resolve() } else { - return Promise.reject('长度不得小于4') + return Promise.reject(new Error('长度不得小于4')) } } diff --git a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue index 4e8232ad..3c509d13 100644 --- a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue +++ b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue @@ -79,7 +79,7 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM if (isPromise(result)) { promises.push( result - .then((res: any) => { + .then((res) => { if (typeof res === 'string') { errors.push({ prop, @@ -94,10 +94,11 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM valid = false } }) - .catch((error) => { + .catch((error: string | Error) => { + const message = typeof error === 'string' ? error : error.message errors.push({ prop, - message: error || rule.message + message: message || rule.message }) valid = false })