gpt4 book ai didi

vue.js - 如何在 VueJs 中将 child 渲染到指定的命名插槽中?

转载 作者:搜寻专家 更新时间:2023-10-30 22:28:42 26 4
gpt4 key购买 nike

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

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

最佳答案

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

关于vue.js - 如何在 VueJs 中将 child 渲染到指定的命名插槽中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44223583/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com