You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/action-custom-event-handler.../main.svelte

31 lines
580 B

<script>
export let items = [[0, 'foo'], [1, 'bar'], [2, 'baz']];
export let first = '';
export let second = '';
export let x = 0;
export let y = 0;
function tap(node, callback) {
function clickHandler(event) {
callback();
}
node.addEventListener('click', clickHandler, false);
return {
destroy() {
node.addEventListener('click', clickHandler, false);
}
};
}
</script>
{#each items as [item0, item1]}
<button use:tap='{() => (first = item0, second = item1)}'>
{item0}: {item1}
</button>
{/each}
<p>first: {first}</p>
<p>second: {second}</p>