メインコンテンツにスキップ

$$slots

ルーンモードでは、コンポーネントにどの スニペット が提供されたかがわかります。それらは通常のプロップだからです。

従来モードでは、特定のスロットにコンテンツが提供されたかどうかを知る方法は $$slots オブジェクトです。そのキーは、親からコンポーネントに渡されたスロットの名前です。

カード
<div>
	<slot name="title" />
	{#if $$slots.description}
		<!-- This <hr> and slot will render only if `slot="description"` is provided. -->
		<hr />
		<slot name="description" />
	{/if}
</div>
アプリ
<Card>
	<h1 slot="title">Blog Post Title</h1>
	<!-- No slot named "description" was provided so the optional slot will not be rendered. -->
</Card>

GitHub でこのページを編集