我有一个带有 title 属性的 BigButton 组件
<script lang="ts">
let title: string;
</script>
<h1 class="text-2xl mb-4 font-extrabold">{title}</h1>
然后在我的index.svelte上,我尝试以不同的方式传递 Prop ,但没有一个起作用:
<BigButton title={'Join a Game'} />
<BigButton title='Join a Game' />
lint 给了我以下错误:
Type '{ title: string; }' is not assignable to type 'IntrinsicAttributes'.
Property 'title' does not exist on type 'IntrinsicAttributes'.
最佳答案
使用应该export
它,例如:
export let title: string;
Svelte uses the
export
keyword to mark a variable declaration as a property or prop, which means it becomes accessible to consumers of the component
关于typescript - 无法使用 TypeScript 将 prop 传递给 svelte 中的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72831023/