美文网首页
Vue 使用 jsx 设置及获取 slot

Vue 使用 jsx 设置及获取 slot

作者: copyLeft | 来源:发表于2020-04-13 17:24 被阅读0次

    父组件设置 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>
    
    

    参考

    相关文章

      网友评论

          本文标题:Vue 使用 jsx 设置及获取 slot

          本文链接:https://www.haomeiwen.com/subject/mkenmhtx.html