Svelte 中的事件传播

问题描述 投票:0回答:1

与子组件交互时,父组件的事件触发。下面是我的代码示例:

<!-- Parent Component -->
<div class="parent" on:click={toggle}>
     {#if expand}
             <Child />
     {/if}
</div>

<!-- Child Component -->
<div class="child" on:mousedown|stopPropagation={execute}>
     text
</div>

我尝试在函数调用中使用

stopPropagation
preventDefault

onclick event-handling svelte mousedown event-propagation
1个回答
0
投票

这些是不同的事件,停止一种类型不会停止另一种,即使它们都与单击操作相关。如果您在家长上听

click
,则必须停止在孩子上
click

另外,使用按钮。

© www.soinside.com 2019 - 2024. All rights reserved.