Access Component Object in External Callback?

2019-08-28 23:10发布

In the following code, in which submit is a method in an external JavaScript module, is it possible for submit() to access the component object?

Component.html

<button on:click={submit}>Submit</button>

<script>
    import { submit } from './';
</script>

index.js

export function submit()
{
    console.log(this); // <button>Submit</button>
};

Before Svelte 3, this would be the component object, but in Svelte 3, this seems to be the target element.

0条回答
登录 后发表回答