图像上的下一步配置

问题描述 投票:0回答:1

如何设置下一个配置以从 http 和 https 协议获取图像

`/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: "https" || "http",
        hostname: "**",
        port: "",
        pathname: "/**",
      },
    ],
  },
};

export default nextConfig;`

但是http好像不起作用

image next.js next-config
1个回答
0
投票

那是因为使用

||
检查一个或多个表达式是否为 true,因为
"https"
被转换为 true,它完全忽略第二个字符串
"http"
,你可以这样做:

/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "**",
        port: "",
        pathname: "/**",
      },
      {
        protocol: "http",
        hostname: "**",
        port: "",
        pathname: "/**",
      },
    ],
  },
};

export default nextConfig;
© www.soinside.com 2019 - 2024. All rights reserved.