2
2
3
3
import { compileToFunctions } from 'vue-template-compiler'
4
4
5
+ function createVNodes (
6
+ vm : Component ,
7
+ slotValue : string
8
+ ) : Array < VNode > {
9
+ const el = compileToFunctions ( `<div>${ slotValue } </div>` )
10
+ const _staticRenderFns = vm . _renderProxy . $options . staticRenderFns
11
+ // version < 2.5
12
+ if ( ! vm . _renderProxy . _staticTrees ) {
13
+ vm . _renderProxy . _staticTrees = [ ]
14
+ }
15
+ vm . _renderProxy . $options . staticRenderFns = el . staticRenderFns
16
+ const vnode = el . render . call ( vm . _renderProxy , vm . $createElement )
17
+ vm . _renderProxy . $options . staticRenderFns = _staticRenderFns
18
+ return vnode . children
19
+ }
20
+
5
21
function createVNodesForSlot (
6
- h : Function ,
22
+ vm : Component ,
7
23
slotValue : SlotValue ,
8
24
name : string ,
9
- vm : Component
10
25
) : VNode | string {
11
26
let vnode
12
27
if ( typeof slotValue === 'string' ) {
13
- const el = compileToFunctions ( `<div>${ slotValue } </div>` )
14
- const _staticRenderFns = vm . _renderProxy . $options . staticRenderFns
15
- // version < 2.5
16
- if ( ! vm . _renderProxy . _staticTrees ) {
17
- vm . _renderProxy . _staticTrees = [ ]
18
- }
19
- vm . _renderProxy . $options . staticRenderFns = el . staticRenderFns
20
- vnode = el . render . call ( vm . _renderProxy , h )
21
- vm . _renderProxy . $options . staticRenderFns = _staticRenderFns
22
- vnode = vnode . children [ 0 ]
28
+ const vnodes = createVNodes ( vm , slotValue )
29
+ vnode = vnodes [ 0 ]
23
30
} else {
24
- vnode = h ( slotValue )
31
+ vnode = vm . $createElement ( slotValue )
25
32
}
26
33
if ( vnode . data ) {
27
34
vnode . data . slot = name
@@ -32,19 +39,18 @@ function createVNodesForSlot (
32
39
}
33
40
34
41
export function createSlotVNodes (
35
- h : Function ,
36
- slots : SlotsObject ,
37
- vm : Component
42
+ vm : Component ,
43
+ slots : SlotsObject
38
44
) : Array < VNode | string > {
39
45
return Object . keys ( slots ) . reduce ( ( acc , key ) => {
40
46
const content = slots [ key ]
41
47
if ( Array . isArray ( content ) ) {
42
48
const nodes = content . map (
43
- slotDef => createVNodesForSlot ( h , slotDef , key , vm )
49
+ slotDef => createVNodesForSlot ( vm , slotDef , key )
44
50
)
45
51
return acc . concat ( nodes )
46
52
}
47
53
48
- return acc . concat ( createVNodesForSlot ( h , content , key , vm ) )
54
+ return acc . concat ( createVNodesForSlot ( vm , content , key ) )
49
55
} , [ ] )
50
56
}
0 commit comments