Post

슬롯을 사용하여 자식 컴포넌트에 접근

♧ 슬롯을 사용하여 자식 컴포넌트에 접근

파일: App.svelte

1
2
3
4
5
<script>
	import Button from './Button.svelte';
</script>

<Button>Text</Button> // Text가 없을 경우, Slot Text 문구가 표시됨...

파일: Button.svelte

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<button><slot>Slot Text</slot></button>

<style>
	button {
		border: none;
		background-color: blue;
		color: white;
		padding: 15px 20px;
		font-weight: bold;
		border-radius: 5px;
		cursor: pointer;
	}
</style>

This post is licensed under CC BY 4.0 by the author.