无法使用打字稿将 prop 传递给苗条的组件

  • 本文关键字:组件 prop typescript svelte
  • 更新时间 :
  • 英文 :


我有一个带有标题道具的BigButton组件

<script lang="ts">
let title: string;
</script>
<h1 class="text-2xl mb-4 font-extrabold">{title}</h1>

然后在我的index.svelte上,我试图以不同的方式传递道具,但都不起作用:

<BigButton title={'Join a Game'} /><BigButton title='Join a Game' />

皮棉给了我以下错误:

Type '{ title: string; }' is not assignable to type 'IntrinsicAttributes'.
Property 'title' does not exist on type 'IntrinsicAttributes'.

应使用exportit,如:

export let title: string;

Svelte使用export关键字将变量声明标记为财产或道具,这意味着消费者可以访问组件

最新更新