如何在React中添加Image?图像不会在localhost上显示

pexxcrt2  于 2023-05-23  发布在  React
关注(0)|答案(1)|浏览(108)

我正在尝试在React中添加一个图像。但我的图像加载不了。
这是我为图像创建的div:

<div>
<Image src={devsimone} />
</div>

我的进口:

import { BsFillMoonStarsFill } from "react-icons/bs";
import { AiFillLinkedin, AiFillGithub, AiOutlineMail } from "react-icons/ai";
import Image from "next/image";
import devsimone from "../public/public/portphoto.png";

下面是我的图像在我的目录中的位置:
Image in directory
我尝试过的步骤:

  • 删除图像并将其添加回
  • 直接从目录中复制粘贴图像路径。
  • 在目录中移动图像。
vuktfyat

vuktfyat1#

由于React知道它的Public目录,因此您可以通过仅定义镜像路径将镜像添加到组件。

<img src="/portphoto.png" alt="image" />

此处的“/”表示公用文件夹。

相关问题