Basic Svelte
Introduction
Bindings
Advanced Svelte
Advanced reactivity
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion
We can also spread event handlers directly onto elements. Here, we’ve defined an onclick
handler in App.svelte
— all we need to do is pass the props to the <button>
in BigRedButton.svelte
:
BigRedButton
<button {...props}>
Push
</button>
previous next
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} />