Image with src "/_next/static/media/…" has legacy prop "layout". Did you forget to run the codemod?

huangapple go评论67阅读模式
英文:

Image with src "/_next/static/media/..." has legacy prop "layout". Did you forget to run the codemod?

问题

我有这段代码

<div className={`w-5 h-5 relative flex-shrink-0 ${additionalClasses}`}>
    <Image src={icon} layout="fill"/>
</div>

我在控制台中得到了这个

Image with src "/_next/static/media/…" has legacy prop "layout". Did you forget to run the codemod?

我没有期望在控制台中看到任何警告。

英文:

I have this code

<div className={`w-5 h-5 relative flex-shrink-0 ${additionalClasses}`}>
    <Image src={icon} layout="fill"/>
</div>

I am getting this in the console

Image with src "/_next/static/media/…" has legacy prop "layout". Did you forget to run the codemod?

I was not expecting anything warning in console

答案1

得分: 1

自从NextJs 13引入了新的Image组件后,layout属性已被弃用。如果您想让您的图像填充父元素,只需使用fill。请参阅文档

<div className={`w-5 h-5 relative flex-shrink-0 ${additionalClasses}`}>
    <Image src={icon} fill/>
</div>
英文:

Since NextJs 13 introduced new Image component, prop layout has been deprecated. If you want to make your image fill the parent, just use fill. Consult with docs

&lt;div className={`w-5 h-5 relative flex-shrink-0 ${additionalClasses}`}&gt;
    &lt;Image src={icon} fill/&gt;
&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年7月10日 17:27:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76652423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定