1 回答
TA贡献1770条经验 获得超3个赞
我假设import { projects } from '../../data'是这样的:
export const data = {
projects: [
{
title: "Project title 1",
category: "frontend development",
description: "",
desktop: [],
mobile: []
}
]
};
projects所以当你映射这个对象时,你需要像这样引用属性data.projects.map()。
例子:
数据.js
export const data = {
projects: [
{
title: "Project title 1",
category: "frontend development",
description: "",
desktop: [],
mobile: []
},
{
title: "Project title 2",
category: "frontend development",
description: "",
desktop: [],
mobile: []
}
]
};
应用程序.js
import React from "react";
import { data } from "./data";
export default function App() {
return (
<div>
{data.projects.map((project, key) => {
return <p key={key}>{project.title}</p>;
})}
</div>
);
}
添加回答
举报