必须导入本地图片。
LocalImageUsedWrongly:
Image
和getImage
的src
参数必须是导入的图片或 URL,不能是字符串文件路径。收到IMAGE_FILE_PATH
。¥LocalImageUsedWrongly:
Image
’s andgetImage
’ssrc
parameter must be an imported image or an URL, it cannot be a string filepath. ReceivedIMAGE_FILE_PATH
.
什么地方出了错?
标题部分 什么地方出了错?¥What went wrong?
使用默认图片服务时,Image
和 getImage
的 src
参数必须是导入的图片或 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:
Error Reference