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/event-handler-custom-each/main.html

35 lines
602 B

{#each items as item}
<button on:tap='set({ fromDom: this.textContent, fromState: item })'>{item}</button>
{/each}
<p>fromDom: {fromDom}</p>
<p>fromState: {fromState}</p>
<script>
export default {
data: () => ({
x: 0,
y: 0,
fromDom: '',
fromState: '',
items: [ 'foo', 'bar', 'baz' ]
}),
events: {
tap ( node, callback ) {
function clickHandler ( event ) {
callback();
}
node.addEventListener( 'click', clickHandler, false );
return {
destroy () {
node.addEventListener( 'click', clickHandler, false );
}
};
}
}
};
</script>