Skip to content

Commit e159cbd

Browse files
committed
feat(vue3-antdv): 添加 on-form-mounted emit,支持获取form组件实例
re #27
1 parent d0a86cf commit e159cbd

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

packages/demo/demo-v2/src/pages/index/views/Demo/index.vue

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
:custom-formats="customFormats"
178178
:form-footer="trueFormFooter"
179179
:form-props="trueFormProps"
180+
@on-form-mounted="handleFormMounted"
180181
@on-change="handleDataChange"
181182
@on-cancel="handleCancel"
182183
@on-submit="handleSubmit"
@@ -377,6 +378,9 @@ export default {
377378
formProps
378379
}));
379380
},
381+
handleFormMounted(formRef) {
382+
console.log('Ui form component:', formRef);
383+
},
380384
handleDataChange() {
381385
console.log('Data change');
382386
},

packages/demo/demo-v3/src/pages/index/views/Demo/index.vue

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
:custom-formats="customFormats"
180180
:form-footer="trueFormFooter"
181181
:form-props="trueFormProps"
182+
@form-mounted="handleFormMounted"
182183
@change="handleDataChange"
183184
@cancel="handleCancel"
184185
@submit="handleSubmit"
@@ -397,6 +398,9 @@ export default {
397398
formProps
398399
}));
399400
},
401+
handleFormMounted(formRef) {
402+
console.log('Ui form component:', formRef);
403+
},
400404
handleDataChange() {
401405
console.log('Data change');
402406
},

packages/docs/docs/zh/guide/basic-config.md

+13
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,19 @@ vue3的版本中为 `change`,去掉 `on` 前缀
752752
表单的值发生改变
753753
> 引用类型,只有重新对对象赋值,否则newVal 等于 oldVal 参见 [vue watch](https://cn.vuejs.org/v2/api/#vm-watch)
754754
755+
### on-form-mounted
756+
* 参数(formRef)
757+
758+
通过该方法可以获取到当前ui框架的form组件实例,可用来执行form组件的一些方法,如(`validate`)
759+
760+
::: warning
761+
vue3的版本中为 `form-mounted`,去掉 `on` 前缀
762+
:::
763+
764+
表单的值发生改变
765+
> 引用类型,只有重新对对象赋值,否则newVal 等于 oldVal 参见 [vue watch](https://cn.vuejs.org/v2/api/#vm-watch)
766+
767+
755768
## 方法 Methods
756769
-- 无
757770

packages/lib/vue2/vue2-core/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ export default function createForm(globalOptions = {}) {
9393
}
9494
},
9595
},
96+
mounted() {
97+
this.$emit('on-form-mounted', this.$refs.genEditForm);
98+
},
9699
render(h) {
97100
const self = this;
98101
// default scoped slot

packages/lib/vue3/vue3-core/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function createForm(globalOptions = {}) {
3232
const Form = {
3333
name: 'VueElementForm',
3434
props: vueProps,
35-
emits: ['update:modelValue', 'change', 'cancel', 'submit', 'validation-failed'],
35+
emits: ['update:modelValue', 'change', 'cancel', 'submit', 'validation-failed', 'form-mounted'],
3636
setup(props, { slots, emit }) {
3737
if (!Form.installed && globalOptions.WIDGET_MAP.widgetComponents) {
3838
// global components
@@ -164,6 +164,7 @@ export default function createForm(globalOptions = {}) {
164164
},
165165
setFormRef: (form) => {
166166
formRef = form;
167+
emit('form-mounted', form);
167168
},
168169
model: rootFormData,
169170
...schemaProps.formProps

0 commit comments

Comments
 (0)