簡體   English   中英

無法使用打字稿將道具傳遞給苗條的組件

[英]Can't pass prop to component in svelte with typescript

我有這個帶有標題道具的 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它,例如:

export let title: string;

Svelte 使用export關鍵字將變量聲明標記為屬性或道具,這意味着組件的使用者可以訪問它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM