Slots 让父组件能够向子组件传递模板内容——这是构建灵活、可复用的包装器(卡片、模态框、布局)的方式,其中使用者控制内部标记。
基本 slot
vue
<!-- Card.vue -->
<template>
<div class="card">
<slot></slot> <!-- parent's content is injected here -->
</div>
</template>
vue
<!-- parent -->
<Card>
<h2>Title</h2> <!-- this markup fills the slot -->
<p>Any content!</p>
</Card>
子组件定义一个"洞"();父组件用它想要的任何标记来填充它。这比通过 props 传递字符串灵活得多。
