Skip to content

必须导入本地图片。

LocalImageUsedWrongly:ImagegetImagesrc 参数必须是导入的图片或 URL,不能是字符串文件路径。收到 IMAGE_FILE_PATH

¥LocalImageUsedWrongly: Image’s and getImage’s src parameter must be an imported image or an URL, it cannot be a string filepath. Received IMAGE_FILE_PATH.

¥What went wrong?

使用默认图片服务时,ImagegetImagesrc 参数必须是导入的图片或 URL,不能是文件路径字符串。

¥When using the default image services, Image’s and getImage’s src parameter must be either an imported image or an URL, it cannot be a string of a filepath.

对于内容集合中的本地图片,你可以使用 image() 模式辅助程序 来解析图片。

¥For local images from content collections, you can use the image() schema helper to resolve the images.

---
import { Image } from "astro:assets";
import myImage from "../my_image.png";
---
<!-- GOOD: `src` is the full imported image. -->
<Image src={myImage} alt="Cool image" />
<!-- GOOD: `src` is a URL. -->
<Image src="https://example.com/my_image.png" alt="Cool image" />
<!-- BAD: `src` is an image's `src` path instead of the full image object. -->
<Image src={myImage.src} alt="Cool image" />
<!-- BAD: `src` is a string filepath. -->
<Image src="../my_image.png" alt="Cool image" />

也可以看看:

¥See Also:

Astro 中文网 - 粤ICP备13048890号