简体   繁体   English

如何将文件夹/文件从公用文件夹导入反应中的 src 文件夹

[英]How to import a folder/file from public folder to src folder in react

Trying to import image folder from public folder to src folder in react but i kept getting error messages in the terminal and my chrome尝试将图像文件夹从公共文件夹导入到 src 文件夹中进行反应,但我一直在终端和我的 chrome 中收到错误消息

[ the vscode screenshot ]( https://i.stack.imgur.com/gtyL0.png ) [ vscode 截图]( https://i.stack.imgur.com/gtyL0.png )

Your image is inside a Image folder.您的图像位于Image文件夹中。 So the import should be所以进口应该是

import Airbnb from '/Images/airbnb.png'

If it gives webpack import error you can do it like this way如果它给出 webpack import 错误,你可以这样做

<img src='/Images/airbnb.png'/>

Here /Images/airbnb.png gives a direct link to the image of the public folder.这里/Images/airbnb.png给出了公共文件夹图像的直接链接。

you need to import from the folder in which the file exists您需要从文件所在的文件夹中导入

import Airbnb from '../../public/Images/airbnb.png'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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