账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue slot嵌套
    25
    0

    父组件中有两个子组件:子组件1 嵌套 子组件2
    且子组件1 和 子组件2 都有<slot>

    结果:
    1.子组件1 slot不写name ,子组件2 slot写 name="content",
    内容可以正常渲染。

    2.子组件1 slot写name="panel" ,子组件2 slot写 name="content",
    只能渲染子组件1的插槽内容。

    3.子组件1 和 子组件2 slot都不写 name,
    内容可以正常渲染。

    请问:为什么会出现这种结果。

    //子组件1: panel.vue
    <template>
    <div>
      <slot name="panel"></slot>
    </div>
    </template>
    
    //子组件2 : content.vue
    <template>
    <div>
      <slot name="content"></slot>
    </div>
    </template>
    
    //父组件
    <template>
    <panel>
      <h1 slot="panel">我是panel</h1>
      <content>
        <p  slot="content">我是content</p>
      </content>
    </panel>
    </template>
    
    <script>
    import Panel from '@/common/panel'
    import Content from '@/common/content'
    </script>
    
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部