【发布时间】:2020-08-23 16:44:23
【问题描述】:
我需要帮助来显示没有导入或任何外部组件的图像。我已经尝试了以下所有方法,但都没有成功。非常感谢您就此事提供任何帮助。
当我使用 require() 时,我收到错误找不到模块 '../assets/images/products
import React from "react";
export default function ProductGallery() {
const products = [
{
ProductImage: "../assets/images/products/image1.jpg",
},
{
ProductImage: "../assets/images/products/image2.jpg",
},
];
return (
<div className="row">
{products.map((item, index) => (
<div className="galleryBox" key={index}>
<img src={require(item.ProductImage)}/>
<img src={require(""+item.ProductImage)}/>
<img src={require(`${item.ProductImage}`)}/>
// all the three methods didnt work
<img src={item.ProductImage}/>
// this doesnt show image at all. When I Inspect, it shows the path correct. But it should come from ../static, however it showing actual path
</div>
))}
<div>
);
}
【问题讨论】:
标签: reactjs