跳到主要內容

我們可以在 Nested.svelte 中輕鬆地為 props 指定預設值

Nested
<script>
	let { answer = 'a mystery' } = $props();
</script>

如果我們現在新增第二個沒有 answer prop 的元件,它將會回退到預設值

App
<Nested answer={42}/>
<Nested />

在 GitHub 上編輯此頁面

上一個 下一個
1
2
3
4
5
6
<script>
	import Nested from './Nested.svelte';
</script>
 
<Nested answer={42} />