File tree 2 files changed +42
-5
lines changed
2 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
15
15
} from '../src'
16
16
import { currentInstance , nextTick , ref } from '@vue/runtime-dom'
17
17
import { makeRender } from './_utils'
18
+ import type { DynamicSlot } from '../src/componentSlots'
18
19
19
20
const define = makeRender < any > ( )
20
21
@@ -468,5 +469,39 @@ describe('component: slots', () => {
468
469
await nextTick ( )
469
470
expect ( html ( ) ) . toBe ( 'content<!--if--><!--slot-->' )
470
471
} )
472
+
473
+ test ( 'dynamic slot work with v-if' , async ( ) => {
474
+ const val = ref ( 'header' )
475
+ const toggle = ref ( false )
476
+
477
+ const Comp = defineVaporComponent ( ( ) => {
478
+ const n0 = template ( '<div></div>' ) ( )
479
+ prepend ( n0 as any as ParentNode , createSlot ( 'header' , null ) )
480
+ return n0
481
+ } )
482
+
483
+ const { host } = define ( ( ) => {
484
+ // dynamic slot
485
+ return createComponent ( Comp , null , {
486
+ $ : [
487
+ ( ) =>
488
+ ( toggle . value
489
+ ? {
490
+ name : val . value ,
491
+ fn : ( ) => {
492
+ return template ( '<h1></h1>' ) ( )
493
+ } ,
494
+ }
495
+ : void 0 ) as DynamicSlot ,
496
+ ] ,
497
+ } )
498
+ } ) . render ( )
499
+
500
+ expect ( host . innerHTML ) . toBe ( '<div><!--slot--></div>' )
501
+
502
+ toggle . value = true
503
+ await nextTick ( )
504
+ expect ( host . innerHTML ) . toBe ( '<div><h1></h1><!--slot--></div>' )
505
+ } )
471
506
} )
472
507
} )
Original file line number Diff line number Diff line change @@ -70,12 +70,14 @@ export function getSlot(
70
70
source = dynamicSources [ i ]
71
71
if ( isFunction ( source ) ) {
72
72
const slot = source ( )
73
- if ( isArray ( slot ) ) {
74
- for ( const s of slot ) {
75
- if ( s . name === key ) return s . fn
73
+ if ( slot ) {
74
+ if ( isArray ( slot ) ) {
75
+ for ( const s of slot ) {
76
+ if ( s . name === key ) return s . fn
77
+ }
78
+ } else if ( slot . name === key ) {
79
+ return slot . fn
76
80
}
77
- } else if ( slot . name === key ) {
78
- return slot . fn
79
81
}
80
82
} else if ( hasOwn ( source , key ) ) {
81
83
return source [ key ]
You can’t perform that action at this time.
0 commit comments