Skip to content

Commit 8fab1f4

Browse files
committed
pref(Form): optimize ProFormComponent
1 parent 642c8ec commit 8fab1f4

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/Form/FormComponent.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
computed,
23
defineComponent,
34
h,
45
mergeProps,
@@ -9,7 +10,7 @@ import {
910
} from 'vue'
1011
import { isFunction, isObject, isString } from '../utils/index'
1112
import { formComponentProps } from './props'
12-
import type { DefineComponent, Slot } from 'vue'
13+
import type { Slot } from 'vue'
1314
import type { StringObject } from '../types/index'
1415

1516
interface TargetEvent {
@@ -27,19 +28,12 @@ export default defineComponent({
2728
const componentRef = ref<StringObject>({})
2829
const componentExpose = reactive<StringObject>({})
2930

30-
onMounted(() => {
31-
Object.assign(componentExpose, componentRef.value)
32-
})
33-
34-
expose(componentExpose)
35-
36-
function getComponent() {
31+
const type = computed(() => {
3732
return isString(props.is) && !nativeComponents.includes(props.is)
3833
? resolveComponent(props.is)
39-
: props.is
40-
}
41-
42-
function getProps() {
34+
: props.is!
35+
})
36+
const componentProps = computed(() => {
4337
const _props: StringObject = mergeProps({ ref: componentRef }, attrs)
4438

4539
if (isString(props.is) && nativeComponents.includes(props.is)) {
@@ -59,9 +53,8 @@ export default defineComponent({
5953
_props.modelValue = undefined
6054
}
6155
return _props
62-
}
63-
64-
function getSlots() {
56+
})
57+
const children = computed(() => {
6558
if (isFunction(props.slots)) {
6659
return props.slots as Slot
6760
} else if (isObject(props.slots)) {
@@ -78,8 +71,14 @@ export default defineComponent({
7871
} else {
7972
return undefined
8073
}
81-
}
74+
})
75+
76+
onMounted(() => {
77+
Object.assign(componentExpose, componentRef.value)
78+
})
79+
80+
expose(componentExpose)
8281

83-
return () => h(getComponent() as DefineComponent, getProps(), getSlots())
82+
return () => h(type.value, componentProps.value, children.value)
8483
},
8584
})

0 commit comments

Comments
 (0)