File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,12 @@ Vue.component('provide-function', {
281281 } )
282282} )
283283
284+ Vue . component ( 'component-with-slot' , {
285+ render ( h ) : VNode {
286+ return h ( 'div' , this . $slots . default )
287+ }
288+ } )
289+
284290Vue . component ( 'component-with-scoped-slot' , {
285291 render ( h ) {
286292 interface ScopedSlotProps {
@@ -301,6 +307,12 @@ Vue.component('component-with-scoped-slot', {
301307 h ( 'child' , {
302308 // Passing down all slots from parent
303309 scopedSlots : this . $scopedSlots
310+ } ) ,
311+ h ( 'child' , {
312+ // Passing down single slot from parent
313+ scopedSlots : {
314+ default : this . $scopedSlots . default
315+ }
304316 } )
305317 ] )
306318 } ,
@@ -320,16 +332,22 @@ Vue.component('narrow-array-of-vnode-type', {
320332 render ( h ) : VNode {
321333 const slot = this . $scopedSlots . default ! ( { } )
322334 if ( typeof slot === 'string' ) {
335+ // <template slot-scope="data">bare string</template>
323336 return h ( 'span' , slot )
324337 } else if ( Array . isArray ( slot ) ) {
338+ // template with multiple children
325339 const first = slot [ 0 ]
326- if ( ! Array . isArray ( first ) && typeof first !== 'string' ) {
340+ if ( ! Array . isArray ( first ) && typeof first !== 'string' && first ) {
327341 return first
328342 } else {
329343 return h ( )
330344 }
331- } else {
345+ } else if ( slot ) {
346+ // <div slot-scope="data">bare VNode</div>
332347 return slot
348+ } else {
349+ // empty template, slot === undefined
350+ return h ( )
333351 }
334352 }
335353} )
Original file line number Diff line number Diff line change 11import { Vue } from "./vue" ;
22
3- export type ScopedSlot = ( props : any ) => VNodeChildrenArrayContents | VNode | string ;
3+ // Scoped slots can technically return anything if used from
4+ // a render function, but this is "good enough" for templates
5+ export type ScopedSlot = ( props : any ) => ScopedSlotChildren ;
6+ export type ScopedSlotChildren = ScopedSlotArrayContents | VNode | string | undefined ;
7+ export interface ScopedSlotArrayContents extends Array < ScopedSlotChildren > { }
48
5- export type VNodeChildren = VNodeChildrenArrayContents | [ ScopedSlot ] | string ;
6- export interface VNodeChildrenArrayContents extends Array < VNode | string | VNodeChildrenArrayContents > { }
9+ // Relaxed type compatible with $createElement
10+ export type VNodeChildren = VNodeChildrenArrayContents | [ ScopedSlot ] | string | boolean | null | undefined ;
11+ export interface VNodeChildrenArrayContents extends Array < VNodeChildren | VNode > { }
712
813export interface VNode {
914 tag ?: string ;
@@ -27,7 +32,7 @@ export interface VNodeComponentOptions {
2732 Ctor : typeof Vue ;
2833 propsData ?: object ;
2934 listeners ?: object ;
30- children ?: VNodeChildren ;
35+ children ?: VNode [ ] ;
3136 tag ?: string ;
3237}
3338
You can’t perform that action at this time.
0 commit comments