snippet
约 124 字小于 1 分钟
2026-09-20
snippet 是指在代码中可以重复使用的代码片段或模板。在 svelte 中,snippet 可以帮助开发者快速插入常用的代码结构,提高开发效率。
我们这里定义了一个 formStep snippet,它接受两个参数:title 和 id,并在模板中使用 @render 去渲染他。
{#snippet formStep({ title, id }: { title: string; id: number })}
<article>
<h2>{title}</h2>
<p>This is a form step with ID: {id}.</p>
</article>
{/snippet}
{@render formStep({ title: 'Step 1', id: 1 })}