1 回答

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊
我假設(shè)import { projects } from '../../data'是這樣的:
export const data = {
? projects: [
? ? {
? ? ? title: "Project title 1",
? ? ? category: "frontend development",
? ? ? description: "",
? ? ? desktop: [],
? ? ? mobile: []
? ? }
? ]
};
projects所以當(dāng)你映射這個(gè)對(duì)象時(shí),你需要像這樣引用屬性data.projects.map()。
例子:
數(shù)據(jù).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: []
? ? }
? ]
};
應(yīng)用程序.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>
? );
}
添加回答
舉報(bào)