相关疑难解决方法(0)

如何在Svelte中动态渲染组件?

我正在尝试循环遍历数组以呈现具有 值的组件type

<script>

import One from './One.svelte';    
import Two from './Two.svelte';
import Three from './Three.svelte';

const contents = [
 {type: 'One'},
 {type: 'Two'},
 {type: 'Three'},
 {type: 'One'}
]

</script>

{#each contents as content}
    <{content.type} />
{/each}
Run Code Online (Sandbox Code Playgroud)

期望的输出:

<One />
<Two />
<Three />
<One />
Run Code Online (Sandbox Code Playgroud)

做这个的最好方式是什么?

svelte

5
推荐指数
1
解决办法
3634
查看次数

标签 统计

svelte ×1