我有一个带有标题道具的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'.
应使用export
it,如:
export let title: string;
Svelte使用
export
关键字将变量声明标记为财产或道具,这意味着消费者可以访问组件