You should place your images folder into the public folder. Also, change the line:
"src": require("../images/merbourne-city.jpg")
to
"src": "/images/merbourne-city.jpg".
Note: The code in countriesExplain.js will display the path of the image. If you want to display the image, you should replace the div with img tag.
data.js
"cities": {
"id-1": {
"name": "Melbpurne",
"src": "/images/merbourne-city.jpg"
}
}
countriesExplain.js
import React from 'react';
import {countries} from "../database/data"
function countriesExplain () {
return (
<>
<div className="">
{countries.map((data, key) => {
return (
<div key={key}>
<div>
{ data.countryCapital }
</div>
<div>
{ data.cities['id-1'].name }
</div>
<img src={ data.cities['id-1'].src }/>
</div>
);
})}
</div>
</>
);
}
export default countriesExplain;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…