您当前的位置: 首页 > 

65Vue - Slots 分发内容(单个 Slot)

杨林伟 发布时间:2019-07-29 11:30:08 ,浏览量:2

除非子组件模板包含至少一个 插口,否则父组件的内容将会被丢弃。当子组件模板只有一个没有属性的 slot 时,父组件整个内容片段将插入到 slot 所在的 DOM 位置,并替换掉 slot 标签本身。

最初在 标签中的任何内容都被视为备用内容。备用内容在子组件的作用域内编译,并且只有在宿主元素为空,且没有要插入的内容时才显示备用内容。

假定 my-component 组件有下面模板:

I'm the child title 如果没有分发内容则显示我。

父组件模版:

I'm the parent title

This is some original content

This is some more original content

渲染结果:

I'm the parent title
I'm the child title

This is some original content

This is some more original content

关注
打赏
1688896170
查看更多评论

杨林伟

暂无认证

  • 2浏览

    0关注

    3183博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.1061s