Skip to main content

Bạn cũng có thể chuyển tiếp cả sự kiện của DOM.

Để được thông báo khi bấm nút <BigRedButton> - ta chỉ cần chuyển tiếp sự kiện click trên phần tử <button> ở trong BigRedButton.svelte:

BigRedButton.svelte
<button on:click>
	Push
</button>

Tiếp theo: Bindings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script>
	import BigRedButton from './BigRedButton.svelte';
	import horn from './horn.mp3';
 
	const audio = new Audio();
	audio.src = horn;
 
	function handleClick() {
		audio.load();
		audio.play();
	}
</script>
 
<BigRedButton on:click={handleClick} />
 
initialising