SvelteIf块

Svelte If 块

HTML没有表达逻辑的方法,比如条件和循环。Svelte 有。为了有条件地呈现一些标记,我们将其包装在一个 ​if​ 块中:{#if user.loggedIn}

<button on:click={toggle}>

Log out

</button>

{/if}

{#if !user.loggedIn}

<button on:click={toggle}>

Log in

</button>

{/if}