渲染错误:Astro 中“无法读取未定义的属性(读取“属性”)”(与 Strapi 结合使用)

问题描述 投票:0回答:1

我尝试导入我在 Strapi 和 Astro 中制作的“日子”。我已经用“标签”和事件做到了。不知道这次出了什么问题。
这是错误的图像:
Error

这是Filter.astro中的代码:

---
const { event, day, } = Astro.props;
import SpeakerList from "../components/SpeakerList.astro";


---
<section class='schedule'>
    <h1>schedule</h1>
    <div class='dates'>
      <p>June - 28th</p>
      <p>June - 29th</p>
      <p>Contiously</p>
      <ul class="tag">
        {event.attributes.days.data.map((tag) => (
            <li key={day.id}>{day.attributes.date}</li>
          ))}
      </ul>    
    </div>
    <SpeakerList />


</section>

这是SpeakerList.astro中的代码

---
import fetchApi from "../lib/strapi";
import SpeakerListCard from "../components/speakerListCard.astro";

const events = await fetchApi({
  endpoint: "events", 
  wrappedByKey: "data", 
  query:{
    populate: ["image", "tags" , "days"]
}});

const tags = await fetchApi({
  endpoint: "tags",
  wrappedByKey: "data",
});

const days = await fetchApi({
  endpoint: "days",
  wrappedByKey: "data",
});

console.log(events);

---

<ul>
    {
      events.map((event) => (
        <li>
          <a href={`/events/${event.id}`}>
            <SpeakerListCard event={event} />
          </a>
        </li>
      ))
    }

</ul>

Json 结构就在这里:
Json

我用虚拟代码尝试了它,allready确实可以工作(标签),但发生了同样的错误......

error-handling attributes strapi astro
1个回答
0
投票

您这里有错字:

 {event.attributes.days.data.map((tag) => (
            <li key={day.id}>{day.attributes.date}</li>
          ))}

day
应该是
tag

© www.soinside.com 2019 - 2024. All rights reserved.