如何在 Next.js 中加载外部图像? [英] How can I load external images in Next.js?

查看:82
本文介绍了如何在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆