イベントハンドラを要素に直接スプレッドすることもできます。ここでは、App.svelte
でonclick
ハンドラを定義しました。必要なのは、BigRedButton.svelte
の<button>
にpropsを渡すことだけです。
BigRedButton
<button {...props}>
Push
</button>
前へ 次へ
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 honk() {
audio.load();
audio.play();
}
</script>
<BigRedButton onclick={honk} />