Svelte 3 中是否存在动态道具 [英] Do dynamic props exist in Svelte 3

查看:26
本文介绍了Svelte 3 中是否存在动态道具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我迭代一个动态组件时:

When I iterate over a dynamic component like:

<svelte:component collection={collection} uid={uid} this={upload_component} 
     bind:action={restart}/>

是否可以为每个组件使用一组动态道具.每个组件都有自己的一组道具名称和道具值.

Is it possible to use a set of dynamic props for each component. Each component having it's own set of prop names and prop values.

解决方案示例:

<script>
    import Info from './Info.svelte';

    const pkgs = [{
        name: 'svelte',
        version: 3,
        speed: 'blazing',
        website: 'https://svelte.dev'
    }, ];
</script>

<Info {...pkgs[0]}/>

更多关于这个 Rich Harris 的回答这里.

More in this Rich Harris answer here.

推荐答案

是的.你需要传播道具:

<svelte:component this={upload_component} bind:action={restart} {...someprops}/>

(注意绑定和事件监听器包含在这些 props 中——但是你总是可以在你的 props 之间传递一个回调函数.)

(Note that bindings and event listeners are not included in those props — but you can always pass down a callback function among your props.)

这篇关于Svelte 3 中是否存在动态道具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆