【发布时间】:2021-03-27 13:55:24
【问题描述】:
我正在尝试在我的组件中使用 Next.js 图像组件进行自动图像优化。
import Image from "next/image";
const PicArrs = () => (
<Image src="remote-location" alt="ViewCrunch" layout="responsive" />
)
但我收到此错误:
错误:带有 SRC“/renmote-location”的图像必须使用“width”和“height”属性或“unsized”属性。
注意: 我希望图像采用 div 的大小,这就是为什么我将其设置为 layout="responsive" 但是当我设置不需要的高度和宽度时,我不会得到这个错误。
我已经阅读了文档,并且如前所述,我什至将布局设置为填充,即使文档说如果布局设置为填充,您不需要 height/width 属性,我仍然会收到此错误。
【问题讨论】:
标签: reactjs next.js nextjs-image