【问题标题】:How to render children into specified named slot in VueJs?如何在 VueJs 中将孩子渲染到指定的命名槽中?
【发布时间】:2017-10-28 15:31:21
【问题描述】:

参考下面的代码,目前所有的孩子都被渲染在默认槽内,即使给出了槽名。

不确定 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>

【问题讨论】:

标签: vue.js render vuejs2 createelement slot


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-06-28
    • 2018-12-06
    • 2022-11-22
    • 2018-01-09
    • 2017-08-03
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多