Skip to main content

$$slots

在符文模式下,我们知道哪些代码片段被提供给组件,因为它们只是普通的属性。

在传统模式下,判断给定槽位是否提供了内容的方法是使用 $$slots 对象,其键是父组件传入的槽位名称。

Card
<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>
App
<Card>
	<h1 slot="title">Blog Post Title</h1>
	<!-- No slot named "description" was provided so the optional slot will not be rendered. -->
</Card>

Edit this page on GitHub llms.txt