如何在VueJs中将子项渲染到指定的命名槽中?

时间:2017-05-28 03:36:14

标签: vue.js render vuejs2 createelement slot

请参阅下面的代码,即使提供了插槽名称,目前所有子代都在默认插槽中呈现。

不确定vue createElement函数是否支持命名槽?

@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)]);
    }
}

当前行为:

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

预期行为:

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

1 个答案:

答案 0 :(得分:0)

确定确实可以在您的选项对象中尝试{slot:'slot-name'}