Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit8c3856e

Browse files
author
Rich Harris
committed
tweak
1 parent7d7157f commit8c3856e

File tree

2 files changed

+13
-7
lines changed
  • content/tutorial/03-advanced-svelte/09-special-elements/02-svelte-component

2 files changed

+13
-7
lines changed

‎content/tutorial/03-advanced-svelte/09-special-elements/02-svelte-component/README.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
title:<svelte:component>
33
---
44

5-
A component can change its category altogether with`<svelte:component>`. Instead of a sequence of`if` blocks...
5+
A component can change its type altogether with`<svelte:component>`. In this exercise, we want to show`RedThing.svelte` if the`color` is`red`,`GreenThing.svelte` if it's`green`, and so on.
6+
7+
We_could_ do this with a sequence of`if` blocks...
68

79
```svelte
810
/// file: App.svelte
@@ -15,11 +17,17 @@ A component can change its category altogether with `<svelte:component>`. Instea
1517
{/if}
1618
```
1719

18-
...we canhave a single dynamic component:
20+
...but it's a little cumbersome. Instead,we cancreate a single dynamic component:
1921

2022
```svelte
2123
/// file: App.svelte
22-
<svelte:component this={selected.component}/>
24+
<select bind:value={selected}>
25+
{#each options as option}
26+
<option value={option}>{option.color}</option>
27+
{/each}
28+
</select>
29+
30+
+++<svelte:component this={selected.component}/>+++
2331
```
2432

2533
The`this` value can be any component constructor, or a falsy value — if it's falsy, no component is rendered.

‎content/tutorial/03-advanced-svelte/09-special-elements/02-svelte-component/app-a/src/lib/App.svelte‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
{#ifselected.color==='red'}
2222
<RedThing />
23-
{:elseifselected.color==='green'}
24-
<GreenThing />
25-
{:elseifselected.color==='blue'}
26-
<BlueThing />
23+
{:else}
24+
<p>TODO others</p>
2725
{/if}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp