我有一个图像数组定义在config.js
. 使用配置文件时,我无法渲染任何图像,但原始 HTML 渲染工作正常。
配置.js
portfolioEntry: [
{
image: '../assets/images/portfolio/solo2.jpg',
service: 'Service text',
address: 'The address'
},
{}
...
]
投资组合.js
import React from "react";
import config from "../../config";
import solo2 from "../assets/images/portfolio/solo2.jpg"; // using this, it is working fine
export default function Portfolio() {
return (
{config.portfolioEntry.map((portfolio, idx) => {
const {image, service, address} = portfolio;
console.log(portfolio);
return (
<div className="box" key={idx}>
<div className="imgBx">
// this is working fine
<img className="img-fluid" src={solo2} alt="not showing"/>
// these is not working
<img className="img-fluid" src={image} alt="not showing"/>
<img className="img-fluid" src={{image}} alt="not showing"/>
</div>
<div className="content">
<h3>{service}</h3>
<p>{address}</p>
</div>
</div>
);
})}
);
}