В качестве быстрого примера кода из https://vuejs.org/v2/guide/components-slots.html#Named-Slots
Допустим, вы хотите сделать данный шаблон с именем 'base-layout'
<div class="container">
<header>
<!-- We want header content here -->
</header>
<main>
<!-- We want main content here -->
</main>
<footer>
<!-- We want footer content here -->
</footer>
</div>
Итак, вы можете видеть, что у нас есть три слота'header', 'main' и 'footer'.
Если вы напишите
<base-layout>
<h1 slot="header">Here might be a page title</h1>
<p>A paragraph for the main content.</p>
<p>And another one.</p>
<p slot="footer">Here's some contact info</p>
</base-layout>
, тогда первое значение тега h1
будет помещено в слот с именем 'header' в нашем шаблоне.И аналогично другим значениям.
Результат будет
<div class="container">
<!-- this is where the 'header' slot was -->
<h1>Here might be a page title</h1>
<!-- this is where the main slot was -->
<p>A paragraph for the main content.</p>
<p>And another one.</p>
<!-- this is where the footer slot was -->
<p>Here's some contact info</p>
Таким образом, слоты в основном похожи на заполнители, которые могут быть названы, и вы можете отправлять информацию точночасть.