![](/img/trans.png)
[英]Why do my Astro builds fail when featuredImage is null?
[英]Getting error "'aspectRatio' must be provided for remote images" when using a local image
在使用本地圖像時,即使在使用 @astrojs/image 集成時在 frontmatter 中導入時,也'aspectRatio' must be provided for remote images
錯誤。 導入的圖片在/src/images
據我所知,這與@astrojs/image 文檔中提供的示例完全相同。 我什至也嘗試過內聯導入方法,但仍然沒有用。
---
import { Picture } from "@astrojs/image/components";
import florence from "../images/florence-3.jpg";
---
<section class="showcase">
<div class="showcase-bg">
<Picture
src={florence}
widths={[200, 400, 800]}
sizes="(max-width: 800px) 100vw, 800px"
alt="Florence Smith Project Manager Picture"
/>
</div>
</section>
謝謝你的幫助!
這是一個與您的代碼相同的工作示例
查看回購中的詳細環境
/pages/picture.astro
---
import MyPicture from '../components/MyPicture.astro';
---
<MyPicture/>
MyPicture.astro
---
import { Picture } from '@astrojs/image/components';
import florence from "../assets/test.png";
---
<Picture
src={florence}
widths={[200, 400, 800]}
sizes="(max-width: 800px) 100vw, 800px"
alt="Florence Smith Project Manager Picture"
/>
github 回購: https ://github.com/MicroWebStacks/astro-examples#16_images
Stackbltiz: https ://stackblitz.com/github/MicroWebStacks/astro-examples/tree/main/16_images
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.