admin管理员组文章数量:1026989
I have tried searching all of the documentation for something about how to use stopPropagation for 'onclick' in Svelte 5, but can find nothing for it other than the legacy stuff. Is there any way to do this in Svelte 5?
I have tried something like this:
<div onclick|stopPropagation={someFunc}>
<button onclick={otherFunc}></button>
</div>
But I get this error: "'onclick|stopPropagation' is not a valid attribute name".
How are you supposed to do this in Svelte 5?
I have tried searching all of the documentation for something about how to use stopPropagation for 'onclick' in Svelte 5, but can find nothing for it other than the legacy stuff. Is there any way to do this in Svelte 5?
I have tried something like this:
<div onclick|stopPropagation={someFunc}>
<button onclick={otherFunc}></button>
</div>
But I get this error: "'onclick|stopPropagation' is not a valid attribute name".
How are you supposed to do this in Svelte 5?
Share Improve this question asked Nov 19, 2024 at 13:07 Lee ManLee Man 7262 gold badges8 silver badges32 bronze badges2 Answers
Reset to default 3I would solve it like this:
<div onclick={(e) => { e.stopPropagation(); someFunc();}}>
<button onclick={otherFunc}></button>
</div>
Modifiers are not supported for event properties. Either call the respective function in the handler directly, or use a higher order function to wrap the handler.
<script>
function someFunc(e) {
e.stopPropagation();
// [other logic]
}
</script>
<button onclick={someFunc}>...
<script>
// extract to a module for reusability
function stopPropagation(handler) {
return e => {
e.stopPropagation();
handler(e);
};
}
function someFunc() { /* ... */ }
</script>
<button onclick={stopPropagation(someFunc)}>...
(There is more info on this in the migration guide.)
I have tried searching all of the documentation for something about how to use stopPropagation for 'onclick' in Svelte 5, but can find nothing for it other than the legacy stuff. Is there any way to do this in Svelte 5?
I have tried something like this:
<div onclick|stopPropagation={someFunc}>
<button onclick={otherFunc}></button>
</div>
But I get this error: "'onclick|stopPropagation' is not a valid attribute name".
How are you supposed to do this in Svelte 5?
I have tried searching all of the documentation for something about how to use stopPropagation for 'onclick' in Svelte 5, but can find nothing for it other than the legacy stuff. Is there any way to do this in Svelte 5?
I have tried something like this:
<div onclick|stopPropagation={someFunc}>
<button onclick={otherFunc}></button>
</div>
But I get this error: "'onclick|stopPropagation' is not a valid attribute name".
How are you supposed to do this in Svelte 5?
Share Improve this question asked Nov 19, 2024 at 13:07 Lee ManLee Man 7262 gold badges8 silver badges32 bronze badges2 Answers
Reset to default 3I would solve it like this:
<div onclick={(e) => { e.stopPropagation(); someFunc();}}>
<button onclick={otherFunc}></button>
</div>
Modifiers are not supported for event properties. Either call the respective function in the handler directly, or use a higher order function to wrap the handler.
<script>
function someFunc(e) {
e.stopPropagation();
// [other logic]
}
</script>
<button onclick={someFunc}>...
<script>
// extract to a module for reusability
function stopPropagation(handler) {
return e => {
e.stopPropagation();
handler(e);
};
}
function someFunc() { /* ... */ }
</script>
<button onclick={stopPropagation(someFunc)}>...
(There is more info on this in the migration guide.)
本文标签: sveltekitNo stopPropagation for Svelte 5Stack Overflow
版权声明:本文标题:sveltekit - No stopPropagation for Svelte 5? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745560556a2156137.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论