反应路线相对文件路径

发布于 2025-02-08 22:12:14 字数 350 浏览 1 评论 0原文

我在组件中导入图像源,并且在本地机器上工作正常。但是,当我将站点上传到服务器时,找不到图像,并且显示出损坏的路径。在路由我的本地计算机上,路径为http:// localhost:3000/static/sedial/myimage.svg在远程服务器上,它是http:http:http:http:http: //remoteserver.com/about/static/media/myimage.svg。这是代码:

import myImage from '../assets/myImage.svg';
...
<img src={myImage} />

I'm importing an image source in a component and it's working fine on my local machine. But when I upload the site to my server the images cannot be found anymore and it shows a broken path. On the route about my local machine the path is http://localhost:3000/static/media/myImage.svg on the remote server it is http://remoteserver.com/about/static/media/myImage.svg. Here's the code:

import myImage from '../assets/myImage.svg';
...
<img src={myImage} />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涙—继续流 2025-02-15 22:12:14

尝试以下操作:

import {ReactComponent as MyImage}from '../assets/myImage.svg';
...
<MyImage />

Try this :

import {ReactComponent as MyImage}from '../assets/myImage.svg';
...
<MyImage />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文