|
1 | | -import type { PropType, ExtractPropTypes, HTMLAttributes } from 'vue'; |
| 1 | +import type { PropType, ExtractPropTypes, HTMLAttributes, ComponentPublicInstance } from 'vue'; |
2 | 2 | import { defineComponent, computed, watch, ref } from 'vue'; |
3 | 3 | import PropTypes from '../_util/vue-types'; |
4 | 4 | import classNames from '../_util/classNames'; |
@@ -89,6 +89,29 @@ export const formProps = { |
89 | 89 |
|
90 | 90 | export type FormProps = Partial<ExtractPropTypes<typeof formProps>>; |
91 | 91 |
|
| 92 | +export type FormExpose = { |
| 93 | + resetFields: (name?: NamePath) => void; |
| 94 | + clearValidate: (name?: NamePath) => void; |
| 95 | + validateFields: ( |
| 96 | + nameList?: NamePath[], |
| 97 | + options?: ValidateOptions, |
| 98 | + ) => Promise<{ |
| 99 | + [key: string]: any; |
| 100 | + }>; |
| 101 | + getFieldsValue: (nameList?: InternalNamePath[] | true) => { |
| 102 | + [key: string]: any; |
| 103 | + }; |
| 104 | + validate: ( |
| 105 | + nameList?: NamePath[], |
| 106 | + options?: ValidateOptions, |
| 107 | + ) => Promise<{ |
| 108 | + [key: string]: any; |
| 109 | + }>; |
| 110 | + scrollToField: (name: NamePath, options?: {}) => void; |
| 111 | +}; |
| 112 | + |
| 113 | +export type FormInstance = ComponentPublicInstance<FormProps, FormExpose>; |
| 114 | + |
92 | 115 | function isEqualName(name1: NamePath, name2: NamePath) { |
93 | 116 | return isEqual(toArray(name1), toArray(name2)); |
94 | 117 | } |
@@ -328,15 +351,14 @@ const Form = defineComponent({ |
328 | 351 | }); |
329 | 352 | } |
330 | 353 | }; |
331 | | - |
332 | 354 | expose({ |
333 | 355 | resetFields, |
334 | 356 | clearValidate, |
335 | 357 | validateFields, |
336 | 358 | getFieldsValue, |
337 | 359 | validate, |
338 | 360 | scrollToField, |
339 | | - }); |
| 361 | + } as FormExpose); |
340 | 362 |
|
341 | 363 | useProvideForm({ |
342 | 364 | model: computed(() => props.model), |
|
0 commit comments