我正在尝试将下一个图像组件添加到我的项目中。
我有一个问题,图像消失时,我添加layout='responsive'
。
验证码:
<Box>
<Link href='/' >
<Image src='/images/logoDark.svg'
alt='navbar-logo'
width={260}
height={56}
layout='responsive'
/>
</Link>
</Box>
有解决办法吗?或者任何其他优化图像的方法?
5条答案
按热度按时间kse8i1jr1#
根据这里发现的(https://github.com/vercel/next.js/issues/19314),似乎
layout='responsive'
没有固有大小。因此,您必须为包含元素添加宽度。hlswsv352#
您需要将
next/image
Package 到包含display:block
的容器中,以便显示图像。camsedfj3#
设置Image组件父级的高度和宽度:
确保父元素在其样式表中使用
display: block
,如Box
组件或div
f45qwnt84#
组件
next.config.js
这对我很有效,图像不会消失,而且有React,
fruv7luv5#
layout = responsive不再有效,已弃用。这是如何在Nextjs中使用Image响应的
确保你用Box Package Image,并给予它一个宽度和高度,如果你在Image中使用'fill' prop,也要给position='relative'}。
图像响应像一个魅力!!!