{#if ...}
{#if expression}...{/if}
{#if expression}...{:else if expression}...{/if}
{#if expression}...{:else}...{/if}
有条件渲染的内容可以封装在 if 块中。
¥Content that is conditionally rendered can be wrapped in an if block.
{#if answer === 42}
<p>what was the question?</p>
{/if}
可以使用 {:else if expression}
添加其他条件,可以选择以 {:else}
子句结尾。
¥Additional conditions can be added with {:else if expression}
, optionally ending in an {:else}
clause.
{#if porridge.temperature > 100}
<p>too hot!</p>
{:else if 80 > porridge.temperature}
<p>too cold!</p>
{:else}
<p>just right!</p>
{/if}
(块不必封装元素,它们也可以封装元素内的文本。)
¥(Blocks don’t have to wrap elements, they can also wrap text within elements.)
上一页 下一页