CompOne 如何运行 CompTwo 中的“test”功能?
CompOne.svelte
<script>
import {test} from './CompTwo.svelte'
</script>
<!-- Some style and HTML tags for this component -->
Run Code Online (Sandbox Code Playgroud)
CompTwo.svelte
<script>
export const test = () => { console.log('testing function') }
</script>
<!-- Some style and HTML tags for this component -->
Run Code Online (Sandbox Code Playgroud)
Ste*_*aes 13
如果您有此组件的实例并绑定到它,则可以运行子函数。
应用程序.svelte
<script>
import Component from './Component.svelte';
let comp;
</script>
<Component bind:this={comp} />
<button on:click={() => comp.test()}>Do Stuff</button>
Run Code Online (Sandbox Code Playgroud)
组件.svelte
<script>
export const test = () => console.log('testing');
</script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6924 次 |
最近记录: |