错误:在反应中找不到模块“ ../img/airlines/Caspian.png”

时间:2019-04-22 20:27:01

标签: reactjs module const require src

在我的react项目中,我有一个const,然后我使用map返回图像

const images=[
{airline: "Aseman",src:'../img/airlines/Aseman.png'},
{airline: "Ata",src:'../img/airlines/Ata.png'},
{airline: "Caspian",src:'../img/airlines/Caspian.png'},
{airline: "IranAir",src:'../img/airlines/IranAir.png'},
{airline: "IranAirTour",src:'../img/airlines/IranAirTour.png'},
{airline: "Karun",src:'../img/airlines/Karun.png'},
{airline: "KishAir",src:'../img/airlines/KishAir.png'},
{airline: "Mahan",src:'../img/airlines/Mahan.png'},
{airline: "Meraj",src:'../img/airlines/Meraj.png'},
{airline: "Qeshm",src:'../img/airlines/Qeshm.png'},
{airline: "Saha",src:'../img/airlines/Saha.png'},
{airline: "Sepehran",src:'../img/airlines/Sepehran.png'},
{airline: "Taban",src:'../img/airlines/Taban.png'},
{airline: "Taftan",src:'../img/airlines/Taftan.png'},
{airline: "Zagros",src:'../img/airlines/Zagros.png'}
];

这是我在const之后的代码:

<img src={require((images.findIndex(x=> x.airline == index.AirLineTitle) > -1 ?  images.find(x=> x.airline == index.AirLineTitle).src : null))} className="Flight-brand" alt=""/>

我的页面中出现此错误:

Error: Cannot find module '../img/airlines/Caspian.png'
webpackEmptyContext
C:/Users/Mehdi/Desktop/travel/src/Flight sync:2
(anonymous function)
C:/Users/Mehdi/Desktop/travel/src/Flight/Flight.js:269
  266 | <Container  className="flight-result ">
  267 |     <Row className="w-100">
  268 |         <Col sm={{span : 2}} >
> 269 |             <img src={require((images.findIndex(x=> x.airline == index.AirLineTitle) > -1 ?  images.find(x=> x.airline == index.AirLineTitle).src : null))} className="Flight-brand" alt=""/>
      | ^  270 |         </Col >
  271 |         <Col sm={{span : 2}} className="flexcenter">
  272 |             <div className="Flight-Details-Time">

0 个答案:

没有答案