Svelte 3 中是否存在动态道具
Do dynamic props exist in Svelte 3
当我迭代动态组件时,例如:
<svelte:component collection={collection} uid={uid} this={upload_component}
bind:action={restart}/>
是否可以为每个组件使用一组动态道具。每个组件都有自己的一组道具名称和道具值。
解决方案示例:
<script>
import Info from './Info.svelte';
const pkgs = [{
name: 'svelte',
version: 3,
speed: 'blazing',
website: 'https://svelte.dev'
}, ];
</script>
<Info {...pkgs[0]}/>
Rich Harris 的回答中有更多内容 。
是的。你需要 spread props:
<svelte:component this={upload_component} bind:action={restart} {...someprops}/>
(请注意,绑定和事件侦听器不包含在这些道具中——但您始终可以在道具中传递回调函数。)
当我迭代动态组件时,例如:
<svelte:component collection={collection} uid={uid} this={upload_component}
bind:action={restart}/>
是否可以为每个组件使用一组动态道具。每个组件都有自己的一组道具名称和道具值。
解决方案示例:
<script>
import Info from './Info.svelte';
const pkgs = [{
name: 'svelte',
version: 3,
speed: 'blazing',
website: 'https://svelte.dev'
}, ];
</script>
<Info {...pkgs[0]}/>
Rich Harris 的回答中有更多内容
是的。你需要 spread props:
<svelte:component this={upload_component} bind:action={restart} {...someprops}/>
(请注意,绑定和事件侦听器不包含在这些道具中——但您始终可以在道具中传递回调函数。)