Skip to main content

자바스크립트에서와 마찬가지로, if 블록에는 else 블록을 추가할 수 있습니다.

App.svelte
{#if count > 10}
	<p>{count} is greater than 10</p>
{:else}
	<p>{count} is between 0 and 10</p>
{/if}

# 문자는 항상 블록 시작 태그를 나타냅니다. / 문자는 항상 블록 종료 태그를 나타냅니다. : 문자는 {:else}에서와 같이 블록 계속 태그를 나타냅니다. 걱정하지 마세요. 스벨트가 HTML에 추가한 문법을 거의 다 배웠습니다.

Next: Else-if 블록

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<script>
	let count = 0;
 
	function increment() {
		count += 1;
	}
</script>
 
<button on:click={increment}>
	Clicked {count}
	{count === 1 ? 'time' : 'times'}
</button>
 
{#if count > 10}
	<p>{count} is greater than 10</p>
{/if}
initialising