问题
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.
来源:https://stackoverflow.com/questions/57571882/access-component-object-in-external-callback