如何在 Next.js 中加载外部图像? [英] How can I load external images in Next.js?
问题描述
JavaScript 并且我正在从 ,域前面似乎不需要协议(https 或 http).试试
module.exports = {图片: {域:['picsum.photos']}};
我还怀疑您的控制台中出现如下错误,正在关闭 这个源码:
<块引用>domains 值必须遵循格式 { domain: 'picsum.photos', ... }
.在此处查看更多信息:https://err.sh/next.js/invalid-i18n-config`
JavaScript and I am loading random images from https://picsum.photos but it is not working. Note that for now, I do not want to use the new image optimization in next.js. Local images are working but external images are not working. Below is my code and my next.config.js
<Slider
{...settingsThumbs}
asNavFor={nav1}
ref={slider => setSlider2(slider)}
>
{slidesData.map(slide => (
<div className='slick-slide' key={slide.id}>
<img
className='slick-slide-image'
src={`https://picsum.photos/800/400?img=${slide.id}`}
alt='sfd'
/>
</div>
))}
</Slider>
below is my next.js config
module.exports = {
images: {
domains: ['https://picsum.photos/']
}
};
Per the docs, the domain does not appear to need a protocol (https or http) in front of it. Try
module.exports = {
images: {
domains: ['picsum.photos']
}
};
I also suspect you have an error like the following in your console, going off this source code:
domains value must follow format
{ domain: 'picsum.photos', ... }
. See more info here: https://err.sh/next.js/invalid-i18n-config`
这篇关于如何在 Next.js 中加载外部图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!