Answers for "svelte else"

6

svelte if else

{#if loaded}
    <h1>Hello World!</h1>
  {:else}
    <h1>Loading...</h1>
{/if}


example 2:
{#if status == 200}
    <h1>Hello World!</h1>
  {:else if status == 401}
    <h1>Not Authorized</h1>
  {:else}
    <h1>Don't know what happened in there</h1>
{/if}
Posted by: Guest on July-26-2021
2

svelte if

{#if x > 10}
	<p>{x} is greater than 10</p>
{:else if 5 > x}
	<p>{x} is less than 5</p>
{:else}
	<p>{x} is between 5 and 10</p>
{/if}
Posted by: Guest on April-11-2021
1

svelte if block

<script>
	let user = { loggedIn: false };
	let toggle = () => user.loggedIn = !user.loggedIn;
</script>

{#if user.loggedIn}
	<button on:click={toggle}>Log out</button>
{/if}

{#if !user.loggedIn}
	<button on:click={toggle}>Log in</button>
{/if}
Posted by: Guest on August-24-2021

Browse Popular Code Answers by Language