【发布时间】:2022-02-08 21:29:50
【问题描述】:
我有一个包含动态内容的组件,如下所示:
<Image width="680" height="400" src={post.imgsrc} alt={post.title} />
即使我添加了宽度/高度,我仍然遇到同样的错误:
src 为“/imgs/paintings/2022/2.jpg”的图像必须使用“width”和“height”属性或“layout='fill'”属性。
我不知道为什么,我想知道为什么我必须指定宽度和高度,因为我的图片有不同的尺寸......
【问题讨论】:
-
您需要提供数值:
<Image width={680} height={400} ...。而要求他们的原因是为了防止cumulative layout shift。 -
非常感谢,不知道这个!
标签: next.js