元素可以用一个特殊的属性 name 来配置如何分发内容。多个 slot 可以有不同的名字。具名 slot 将匹配内容片段中有对应 slot 特性的元素。
仍然可以有一个匿名 slot ,它是默认 slot ,作为找不到匹配的内容片段的备用插槽。如果没有默认的 slot ,这些找不到匹配的内容片段将被抛弃。
例如,假定我们有一个 app-layout 组件,它的模板为:
父组件模版:
Here might be a page title
A paragraph for the main content.
And another one.
Here's some contact info
渲染结果为:
Here might be a page title
A paragraph for the main content.
And another one.
Here's some contact info
在组合组件时,内容分发 API 是非常有用的机制。