mirror of https://github.com/sveltejs/svelte
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.
22 lines
330 B
22 lines
330 B
7 years ago
|
<button use:foo>{{x}}</button>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
|
actions: {
|
||
|
foo(node) {
|
||
|
let x = 0;
|
||
|
|
||
|
const handler = () => this.set({ x: x++ });
|
||
|
|
||
|
node.addEventListener('click', handler);
|
||
|
handler();
|
||
|
|
||
|
return {
|
||
|
destroy() {
|
||
|
node.removeEventListener('click', handler);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
},
|
||
|
};
|
||
|
</script>
|