简体   繁体   English

图像未从本地显示

[英]Image is not displaying from local

在此处输入图片说明 I want to display the image from my local , but it is showing like this.我想从我的本地显示图像,但它是这样显示的。

在此处输入图片说明

I don't understand what is wrong here!我不明白这里有什么问题!

The below img code i'm using in provider.js file我在 provider.js 文件中使用的以下img代码

 <img src='../../../public/icons/videoOn.png'/>

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.

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