@@ -137,7 +137,7 @@ const model = reactive<{
137137
138138const form = ref ()
139139
140- function handleSubmit1 () {
140+ function handleSubmit () {
141141 form .value
142142 .validate ()
143143 .then (({ valid , errors }) => {
@@ -154,7 +154,6 @@ function handleSubmit1() {
154154< / script >
155155```
156156
157-
158157:::
159158
160159## 校验规则
@@ -403,62 +402,59 @@ const submit = () => {
403402::: code-group
404403
405404``` html [vue]
406- <wd-form ref =" form" :model =" model" >
405+ <wd-form ref =" form" :model =" model" errorType = " toast " >
407406 <wd-cell-group border >
408407 <wd-input
409408 label =" 用户名"
410409 label-width =" 100px"
411- prop =" name "
410+ prop =" value1 "
412411 clearable
413- v-model =" model.name "
412+ v-model =" model.value1 "
414413 placeholder =" 请输入用户名"
415- @blur =" handleBlur('name')"
416414 :rules =" [{ required: true, message: '请填写用户名' }]"
417415 />
418416 <wd-input
419- label =" 联系方式"
420- prop =" phoneNumber"
417+ label =" 密码"
421418 label-width =" 100px"
419+ prop =" value2"
420+ show-password
422421 clearable
423- @blur =" handleBlur('phoneNumber')"
424- v-model =" model.phoneNumber"
425- placeholder =" 联系方式"
426- :rules =" [{ required: true, message: '请填写联系方式' }]"
422+ v-model =" model.value2"
423+ placeholder =" 请输入密码"
424+ :rules =" [{ required: true, message: '请填写密码' }]"
427425 />
428426 </wd-cell-group >
427+ <view class =" footer" >
428+ <wd-button type =" primary" size =" large" @click =" handleSubmit" block >提交</wd-button >
429+ </view >
429430</wd-form >
430-
431- <view class =" footer" >
432- <wd-button type =" primary" size =" large" block @click =" handleSubmit" >提交</wd-button >
433- </view >
434431```
435432
436433``` typescript [typescript]
437434< script lang = " ts" setup >
438435import { useToast } from ' @/uni_modules/wot-design-uni'
436+ import type { FormInstance } from ' @/uni_modules/wot-design-uni/components/wd-form/types'
439437import { reactive , ref } from ' vue'
440438
439+ const { success : showSuccess } = useToast ()
441440const model = reactive <{
442- name : string
443- phoneNumber : string
441+ value1 : string
442+ value2 : string
444443}>({
445- name : ' ' ,
446- phoneNumber : ' '
444+ value1 : ' ' ,
445+ value2 : ' '
447446})
448447
449- const { success : showSuccess } = useToast ()
450- const form = ref ()
451-
452- function handleBlur(prop : string ) {
453- form .value .validate (prop )
454- }
448+ const form = ref <FormInstance >()
455449
456450function handleSubmit() {
457- form . value
458- .validate ()
459- .then (({ valid }) => {
451+ form
452+ .value ! . validate ()
453+ .then (({ valid , errors }) => {
460454 if (valid ) {
461- showSuccess (' 校验通过' )
455+ showSuccess ({
456+ msg: ' 校验通过'
457+ })
462458 }
463459 })
464460 .catch ((error ) => {
@@ -573,7 +569,15 @@ function handleSubmit() {
573569 <wd-switch v-model =" model.switchVal" />
574570 </view >
575571 </wd-cell >
576- <wd-input label =" 歪比巴卜" label-width =" 100px" prop =" cardId" suffix-icon =" camera" placeholder =" 请输入歪比巴卜" clearable v-model =" model.cardId" />
572+ <wd-input
573+ label =" 歪比巴卜"
574+ label-width =" 100px"
575+ prop =" cardId"
576+ suffix-icon =" camera"
577+ placeholder =" 请输入歪比巴卜"
578+ clearable
579+ v-model =" model.cardId"
580+ />
577581 <wd-input label =" 玛卡巴卡" label-width =" 100px" prop =" phone" placeholder =" 请输入玛卡巴卡" clearable v-model =" model.phone" />
578582 <wd-cell title =" 活动图片" title-width =" 100px" prop =" fileList" >
579583 <wd-upload :file-list =" model.fileList" action =" https://ftf.jd.com/api/uploadImg" @change =" handleFileChange" ></wd-upload >
@@ -916,12 +920,12 @@ function handleIconClick() {
916920
917921## Attributes
918922
919- | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
920- | ----- | ------------ | --------------------- | ------ | ------ | -------- |
921- | model | 表单数据对象 | ` Record<string, any> ` | - | - | 0.2.0 |
922- | rules | 表单验证规则 | ` FormRules ` | - | - | 0.2.0 |
923- | resetOnChange | 表单数据变化时是否重置表单提示信息(设置为false时需要开发者单独对变更项进行校验 ) | ` boolean ` | - | ` true ` | 0.2.16 |
924- | errorType | 校验错误提示方式 | ` toast/message/none ` | - | ` message ` | $LOWEST_VERSION$ |
923+ | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
924+ | ------------- | ----------------------------------------------------------------------------------- | --------------------- | ------ | --------- | -------- -------- |
925+ | model | 表单数据对象 | ` Record<string, any> ` | - | - | 0.2.0 |
926+ | rules | 表单验证规则 | ` FormRules ` | - | - | 0.2.0 |
927+ | resetOnChange | 表单数据变化时是否重置表单提示信息(设置为 false 时需要开发者单独对变更项进行校验 ) | ` boolean ` | - | ` true ` | 0.2.16 |
928+ | errorType | 校验错误提示方式 | ` toast/message/none ` | - | ` message ` | $LOWEST_VERSION$ |
925929
926930### FormItemRule 数据结构
927931
0 commit comments