当我遍历动态组件时,例如:
<svelte:component collection={collection} uid={uid} this={upload_component}
bind:action={restart}/>
是否可以为每个组件使用一组动态 Prop 。每个组件都有自己的一组 prop 名称和 prop 值。
解决方案示例:
<script>
import Info from './Info.svelte';
const pkgs = [{
name: 'svelte',
version: 3,
speed: 'blazing',
website: 'https://svelte.dev'
}, ];
</script>
<Info {...pkgs[0]}/>
Rich Harris 回答中的更多信息 here .
最佳答案
是的。你需要spread props :
<svelte:component this={upload_component} bind:action={restart} {...someprops}/>
(请注意,绑定(bind)和事件监听器不包含在这些 Prop 中——但您始终可以在 Prop 中传递回调函数。)
关于svelte - Svelte 3 中是否存在动态 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58115156/