最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Importing images from public folder in react - Stack Overflow

programmeradmin0浏览0评论

OK last hail mary here. I've seen this question a lot but no clear answer. I moved all of my images out of my src folder to my public folder into a sub-folder images. And used the URL like ./images/my-image.png but the image isn't populating. I am using create-react-app. How do I call images from a public folder outside of my src folder.

OK last hail mary here. I've seen this question a lot but no clear answer. I moved all of my images out of my src folder to my public folder into a sub-folder images. And used the URL like ./images/my-image.png but the image isn't populating. I am using create-react-app. How do I call images from a public folder outside of my src folder.

Share Improve this question asked Apr 15, 2022 at 7:59 frankieseattlefrankieseattle 1813 silver badges17 bronze badges 1
  • 1 Does this answer your question? ReactJS and images in public folder – Mohammad Hooshdar Commented Apr 15, 2022 at 8:04
Add a ment  | 

2 Answers 2

Reset to default 2

change the src from /public/images to /images

This is what worked for me:

src:(process.env.PUBLIC_URL+"/images/image-name.jpg")
发布评论

评论列表(0)

  1. 暂无评论