简体   繁体   中英

How do I get image data from local JSON file data?

I have a JSON file in public folder and image in src/assets/img/ If I had to do it with reactjs, I can just do:

import flat from "../../../assets/img/two.jpg";

And in JSON file, I gave the exact location of the image file but it cannot locate image

"apartment_image":"../../../assets/img/two.jpg"

Now it cannot find the image file. My code looks like this:

<div className="img-section">
        <img className="flat-image" src={data.apartment_image} alt="" />
      </div>

Everything loads except the image.

I should give absolute path to get the image... Like this: " http://localhost:3000/flat-trade/img/two.jpg "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM