1
1
import {
2
+ computed ,
2
3
defineComponent ,
3
4
h ,
4
5
mergeProps ,
@@ -9,7 +10,7 @@ import {
9
10
} from 'vue'
10
11
import { isFunction , isObject , isString } from '../utils/index'
11
12
import { formComponentProps } from './props'
12
- import type { DefineComponent , Slot } from 'vue'
13
+ import type { Slot } from 'vue'
13
14
import type { StringObject } from '../types/index'
14
15
15
16
interface TargetEvent {
@@ -27,19 +28,12 @@ export default defineComponent({
27
28
const componentRef = ref < StringObject > ( { } )
28
29
const componentExpose = reactive < StringObject > ( { } )
29
30
30
- onMounted ( ( ) => {
31
- Object . assign ( componentExpose , componentRef . value )
32
- } )
33
-
34
- expose ( componentExpose )
35
-
36
- function getComponent ( ) {
31
+ const type = computed ( ( ) => {
37
32
return isString ( props . is ) && ! nativeComponents . includes ( props . is )
38
33
? resolveComponent ( props . is )
39
- : props . is
40
- }
41
-
42
- function getProps ( ) {
34
+ : props . is !
35
+ } )
36
+ const componentProps = computed ( ( ) => {
43
37
const _props : StringObject = mergeProps ( { ref : componentRef } , attrs )
44
38
45
39
if ( isString ( props . is ) && nativeComponents . includes ( props . is ) ) {
@@ -59,9 +53,8 @@ export default defineComponent({
59
53
_props . modelValue = undefined
60
54
}
61
55
return _props
62
- }
63
-
64
- function getSlots ( ) {
56
+ } )
57
+ const children = computed ( ( ) => {
65
58
if ( isFunction ( props . slots ) ) {
66
59
return props . slots as Slot
67
60
} else if ( isObject ( props . slots ) ) {
@@ -78,8 +71,14 @@ export default defineComponent({
78
71
} else {
79
72
return undefined
80
73
}
81
- }
74
+ } )
75
+
76
+ onMounted ( ( ) => {
77
+ Object . assign ( componentExpose , componentRef . value )
78
+ } )
79
+
80
+ expose ( componentExpose )
82
81
83
- return ( ) => h ( getComponent ( ) as DefineComponent , getProps ( ) , getSlots ( ) )
82
+ return ( ) => h ( type . value , componentProps . value , children . value )
84
83
} ,
85
84
} )
0 commit comments