【发布时间】:2021-09-09 01:54:04
【问题描述】:
在我的 App.svelte 中,我的函数中有以下代码:
<script>
import Categories from "./Categories.svelte";
let choice = { category: false };
export function toggle() {
choice.category = !choice.category;
}
</script>
{#if choice.category}
<Categories />
{:else}
<p>Foo.</p>
{/if}
在我的类别组件中,我有以下代码:
<button id="vegetation" on:click="toggle()">
<span>Analyse vegetation and forestry</span>
</button>
我想要的是:当我点击类别组件中的按钮时,应该调用toggle()函数。
我该怎么做?
【问题讨论】:
-
您可以转发点击事件(不使用调度程序)。教程中的示例:svelte.dev/tutorial/dom-event-forwarding