Skip to content

Commit db32ef9

Browse files
feat: ✨ Form 校验规则validator支持传入Error作为校验提示
Closes: #667
1 parent 8c0e978 commit db32ef9

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/pages/form/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const validator = (val: any) => {
149149
if (String(val).length >= 4) {
150150
return Promise.resolve()
151151
} else {
152-
return Promise.reject('长度不得小于4')
152+
return Promise.reject(new Error('长度不得小于4'))
153153
}
154154
}
155155

src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM
7979
if (isPromise(result)) {
8080
promises.push(
8181
result
82-
.then((res: any) => {
82+
.then((res) => {
8383
if (typeof res === 'string') {
8484
errors.push({
8585
prop,
@@ -94,10 +94,11 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM
9494
valid = false
9595
}
9696
})
97-
.catch((error) => {
97+
.catch((error: string | Error) => {
98+
const message = typeof error === 'string' ? error : error.message
9899
errors.push({
99100
prop,
100-
message: error || rule.message
101+
message: message || rule.message
101102
})
102103
valid = false
103104
})

0 commit comments

Comments
 (0)