父组件设置 slot
render(){
const slotName = 'topbar' || 'default'
const scopeSlotChild = this.$slots[slotName]
return (
<div> { scopeSlotChild } </div>
)
}
父组件设置 slot-scope
render(){
const scopedSlots = {
// 默认插槽
default: slotProps => [ <Cmp slotprops={slotprops} /> ],
// 具名插槽
footer: slotProps => [ <Button slotprops={slotprops} /> ]
}
}
子组件获取 slotProps
<parent
{ ...{
scopedSlots: {
default: scope => {
return <div>{this.scope.data}</div>
}
}
}
>
</parent>
网友评论