[英]Image is not displaying from local
Don't use path as src
, because it must be accessible via web.不要使用 path 作为
src
,因为它必须可以通过 web 访问。
Means you need src="http://example.com/public/icons/videoOn.png"
or src="/public/icons/videoOn.png"
意味着你需要
src="http://example.com/public/icons/videoOn.png"
或src="/public/icons/videoOn.png"
In that situation always check Network tab and see from where your browser tries to get file.在这种情况下,请始终检查网络选项卡并查看浏览器尝试从何处获取文件。 You must be able to go to same URL and access file
您必须能够访问相同的 URL 并访问文件
After looking at the screenshot, this looks like a React JS project.查看截图后,这看起来像一个 React JS 项目。 For static assets, you need to import them, but only when they're inside the
src
folder.对于静态资源,您需要导入它们,但
src
是它们位于src
文件夹中。 If they're inside the public
folder, you can do this:如果它们在
public
文件夹中,您可以执行以下操作:
<img src='/icons/videoOn.png' />
The above code should work for you.上面的代码应该适合你。 If you're deploying it to a non-root and should be safer, then use
process.env.PUBLIC_URL
:如果您将其部署到非 root 用户并且应该更安全,请使用
process.env.PUBLIC_URL
:
<img src={process.env.PUBLIC_URL + '/icons/videoOn.png'} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.