【发布时间】: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>
【问题讨论】:
-
我一直在努力让 'h(COMP, null, { default: 90=>..., otherSlots: .()=>...}` 工作,但 vuejs 并没有用内容
-
已确认 vue2 v Vue3 对我的问题:vue2:vuejs.org/v2/guide/render-function.html 子参数不接受对象表示法 vue3:v3.vuejs.org/guide/render-function.html#h-arguments 子参数具有对象支持 HTH
标签: vue.js render vuejs2 createelement slot