首页 > 解决方案 > 图像在下一个 js 中不起作用。给出错误“主机名”

问题描述

使用下一个 js Image 时,会出现错误

next.config.js:

module.exports = {
  images: {
    domains: ['localhost'],
  },
};

错误图片:在此处输入图像描述

我真的不明白如何设置 img 以及下一个 js 想从我这里得到什么

图片组件代码:

        <Image         
        alt={element.show_name_eng}
        src={'\\' + element.show_picture_1980} - throws an error if not - //

but it works without problems if you use picture + source
        width={200}
        height={100}/>

标签: javascriptreactjsnext.js

解决方案


您应该在此代码中添加图像的基本 URL

module.exports = {
  images: {
    domains: ['localhost','https://example.cm'],
  },
};

推荐阅读