Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render children into specified named slot in VueJs?

Refer to the code below, currently all the children were rendered inside the default slot even though the slot name is given.

Not sure whether vue createElement function supports named slot?

@Component({
    props:[]
})
export class TestComponent extends Widget{
    items:any[];
    render(h:any){
        const rootcmp = {
            template:`<div>
                Temp:<slot name="temp"></slot>
                Default:<slot></slot>
            </div>`
            , data:()=>{
                return {};
            }
        }
        const cmp = {
            template:'<div slot="default">This is child</div>'
            , data:()=>{
                return {};
            }
        }
        const cmp2 = {
            template:'<div slot="temp">This is child</div>'
            , data:()=>{
                return {};
            }
        }
        return h(rootcmp, [h(cmp), h(cmp2)]);
    }
}

Current behavior:

<div>
Temp:Default:
<div>This is child</div>
<div>This is child</div>
</div>

Expected behavior:

<div>
Temp:
<div>This is child</div>
Default:
<div>This is child</div>
</div>
like image 778
mind1n Avatar asked May 28 '17 03:05

mind1n


1 Answers

It sure does, in your options object, try {slot:'slot-name'}

like image 200
Screll Avatar answered Oct 05 '22 07:10

Screll