File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
docs/src/components/common-ui Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -518,20 +518,25 @@ import { z } from '#/adapter/form';
518
518
519
519
// 可选(可以是undefined),并且携带默认值。注意zod的optional不包括空字符串''
520
520
{
521
- rules : z .string ().default (' 默认值' ).optional (),
521
+ rules : z .string ().default (' 默认值' ).optional ();
522
522
}
523
523
524
- // 可以是空字符串、undefined或者一个邮箱地址
524
+ // 可以是空字符串、undefined或者一个邮箱地址(两种不同的用法)
525
525
{
526
- rules : z .union (z .string ().email ().optional (), z .literal (" " ))
526
+ rules : z .union ([z .string ().email ().optional (), z .literal (' ' )]);
527
+ }
528
+
529
+ {
530
+ rules : z .string ().email ().or (z .literal (' ' )).optional ();
527
531
}
528
532
529
533
// 复杂校验
530
534
{
531
- z .string ().min (1 , { message: " 请输入" })
532
- .refine ((value ) => value === " 123" , {
533
- message: " 值必须为123" ,
534
- });
535
+ z .string ()
536
+ .min (1 , { message: ' 请输入' })
537
+ .refine ((value ) => value === ' 123' , {
538
+ message: ' 值必须为123' ,
539
+ });
535
540
}
536
541
```
537
542
You can’t perform that action at this time.
0 commit comments