Vue 实现了一套内容分发的 API,这套 API 的设计灵感源自 Web Components 规范草案,将 元素作为承载分发内容的出口。 它允许你像这样合成组件:<todo-button> Add todo </todo-button> 然后在 的模板中,你可能有:<!-- todo-button 组件模板 --> <button class="btn-primary"> <slot></slot> </button> 当组件渲染的时候, 将会被替换为“Add Todo”。<!-- 渲染 HTML --> <button class="btn-primary"> Add todo </button> 不过,字符串只是开始!插槽还可以包含任何模板代码,包括 HTML:<todo-button> <!-- 添加一个Font Awesome 图标 --> <i class="fas fa...