我想使用动态组件根据枚举的值选择视图:
如何正确地指定动态组件的类型?
UPD:React 中的 map 示例
<svelte:component
this={components[enumValue]}
{...props}
/>
但是如果我没有传递所有必要的参数,我就不会收到编译错误:
<svelte:component
this={components[enumValue]}
/>
如何正确地指定动态组件的类型?
UPD:React 中的 map 示例
const props: Props = {...}
const components: Record<EnumType, React.FC<Props>> = {
[EnumType.variant_1]: Component1,
[EnumType.variant_2]: Component2,
}
bind
。通常情况下,使用svelte:component
应该是一个罕见的事件,因此您应该选择权衡。UPD是什么?另外,您已经拥有“组件类型”,它是从Svelte文件中导入的内容。 - H.B.SvelteComponentTyped
现已被弃用,而且我无法让这个提议的解决方案起作用 - 有什么想法吗?(使用Svelte 4.2.1) - undefined