admin管理员组文章数量:1289583
I was wondering if it's possible to have access to entire object inside if/for, but still be able to destructure individual props
{#if object_var}
{const {prop_var} = object_var}. <- doesn't work, "unexpected token"
display: {prop_var}
{/if}
I was wondering if it's possible to have access to entire object inside if/for, but still be able to destructure individual props
{#if object_var}
{const {prop_var} = object_var}. <- doesn't work, "unexpected token"
display: {prop_var}
{/if}
Share
Improve this question
asked Feb 20 at 18:53
AlexAlex
68.1k185 gold badges459 silver badges650 bronze badges
1
- what token is unexpected? the dot? – Nina Scholz Commented Feb 20 at 18:58
1 Answer
Reset to default 1Without any leading symbol, the curly braces signal a text expression. You cannot use arbitrary JS there; regular declarations are not allowed.
There is a @const
tag that can be used in some specific places.
Here this would work since the tag is an immediate child of #if
:
{#if object_var}
{@const { prop_var } = object_var}
display: {prop_var}
{/if}
本文标签: javascriptDestructure and don39t destructure variable at the same time in svelteStack Overflow
版权声明:本文标题:javascript - Destructure and don't destructure variable at the same time in svelte - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741412989a2377347.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论