除非子组件模板包含至少一个 插口,否则父组件的内容将会被丢弃。当子组件模板只有一个没有属性的 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