【发布时间】:2026-01-26 12:55:02
【问题描述】:
我的网络应用程序没有从我的对象数组中渲染图像。我尝试了require 方法,但没有成功。这是我的文件夹结构
我的数组现在看起来像这样。我不知道它是否是错误的文件夹路径,但它看起来相对正确,所以如果我需要以某种方式使用 require 方法,那将如何更改我的路径名
export const Projects = [
{
id: "intuition",
name: "inTuition website",
tags: ["Financial Markets", "Express", "Mongo DB"],
description: "Team App was a concept project for a team communication website. I made it through Webflow and took advantage of their powerful CMS platform to create a blog section that management can update on their timeline without a developer. This Application is fully responsive and highlights the foundational principles behind a reliable website for a growing company.",
pageDescription: "Intuition is an online global money transfer application for international students who want a faster, and more secure way to transfer money from their home nation to their school. inTuition is commited to developing inovative technologies that make the global financial markets more convinient for end users.",
thumbnail: '../pages/images/team2.png',
mockup: '../pages/images/team-fs.jpg',
link: '/experience/intuition'
},
{
id: "savona",
name: "Savona website",
tags: ["Restaurant", "Webflow", "Content-Management-System"],
description: "Savona is a local pizza restaurant in Calgary that serves the most delicious pizza, and I am excited to build their first website. I designed a modern website that reenforces Savona's culture, brand and identity. I integrated a robust online ordering process using moduurn to enable customers to order online and add a new avenue of revenue for the company",
pageDescription: "Savona is a local pizza restaurant in Calgary that serves the most delicious pizza, and I am excited to build their first website. I designed a modern website that reenforces Savona's culture, brand and identity. I integrated a robust online ordering process using moduurn to enable customers to order online and add a new avenue of revenue for the company",
thumbnail: "../pages/images/savona-thumbnail.png",
mockup: '../pages/images/savona.png',
link: '/experience/savona'
},
{
id: "teamapp",
name: "Team App website",
tags: ["Concept", "Responsive", "Blog"],
description: "Team App was a concept project for a team communication website. I made it through Webflow and took advantage of their powerful CMS platform to create a blog section that management can update on their timeline without a developer. This Application is fully responsive and highlights the foundational principles behind a reliable website for a growing company.",
pageDescription: "Team App was a concept project for a team communication website. I made it through Webflow and took advantage of their powerful CMS platform to create a blog sect",
thumbnail: '../pages/images/team2.png',
mockup: '../pages/images/team-fs.jpg',
link: '/experience/teamapp'
}
]
动态呈现这个的页面看起来像这样
import React from "react";
import Footer from '../components/Footer'
import Navbar from '../components/Navbar'
import { Projects } from '../Database/Projects'
export default function ExperiencePage({ match }) {
function expPlace(exp) {
return exp.id === match.params.id
}
const place = Projects.find(expPlace)
return (
<div>
<div class="header">
<Navbar />
<div class="header-wrapper">
<div class="container center">
<h4>project showcase</h4>
<h1>{place.id}</h1>
<p class="header-paragraph">{place.pageDescription}</p>
{/* <a href="#" class="live-site-link yellow-link">visit live site →</a> */}
</div>
</div>
</div>
<div class="section">
<div class="screen-container">
<img alt="A screenshot of web page" src={place.mockup} class="screen-image" />
</div>
</div>
<Footer />
</div>
)
}
【问题讨论】:
-
控制台中应该有一个错误,图像为 404。在那里你可以看到它试图找到的确切路径。浏览器是否在正确的文件夹中查找图像?
-
要指定类,您需要使用
className而不是class,但至于您的图像问题,我想应该归咎于相对路径。 -
所以如果我像这样将 require 添加到 src...src={require(place.mockup)}... 那么我得到这个错误:找不到模块'../pages/images /团队-fs.jpg'。但是,如果我不需要它,那么就没有错误,它只会显示 alt-text
标签: javascript reactjs