在上一个问题中,作者尝试加载标准 DOM img
:
cloudinary image doesn't show up
答案是指定cloudName
和publicId
支持Image
-
<Image cloudName="doqurzmbt" publicId="public id from cloudinary" ... >
我正在尝试使用 NextImage
组件来处理 Cloudinary 图像:
- 填写
next.config.js
:
module.exports = {
images: {
deviceSizes: [300, 640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
domains: ["res.cloudinary.com"],
loader: "cloudinary",
},
};
- 编写示例代码:
import Image from "next/image";
export default function Page() {
return (
<>
<p>Simple cloudinary example</p>
<p>Standart image</p>
<img
src="https://res.cloudinary.com/dljazkzna/image/upload/v1604677935/img/1053.jpg"
alt=""
width="200"
/>
<p>NextJS Image component</p>
<Image
alt="Cloudinary image"
cloudName="dljazkzna"
publicId="img/1053"
width={300}
height={300}
src="1053.jpg"
/>
</>
);
}
Codesandbox 链接: https ://codesandbox.io/s/nextjs-cloudinary-779pr?file=/pages/index.js
问题:
Image
组件不显示图像。根据文档:
https://nextjs.org/docs/api-reference/next/image
cloudName
组件中publicId
没有道具Image
。
我需要传递给 NextImage
组件的参数是什么?
Cloudinary 图像具有以下属性:
src="https://res.cloudinary.com/dljazkzna/image/upload/v1604677935/img/1053.jpg"
cloudName="dljazkzna"
publicId="img/1053"