在 Astro 组件上使用数组

Emm*_*uel 2 javascript arrays dictionary

我在使用组件上的地图时遇到问题

  1. 全新安装(npm create astro@latest),基础版,无typescript(不知道有没有必要)

src/components/Card.astro

---
export interface Props {

    items: Array<string>;
}

const { items } = Astro.props as Props;
---

<ol>
 {items.map((item) => (
  <li>{item}</li>
 ))}
</ol>

Run Code Online (Sandbox Code Playgroud)

src/pages/index.Astro

import Card from '../components/Card.astro';
---
<Card
 items=["a"]
/>
Run Code Online (Sandbox Code Playgroud)

错误:错误:应为“}”,但找到了“a”

提前致谢

小智 5

使用<Card items={["a"]} />因为没有花括号 astro 认为您正在编写 html 代码。