简体   繁体   English

如何使用 NextJS Image Component 显示通过 props 接收到的图片?

[英]How to use NextJS Image Component to display images receiving through props?

Simply I wanna display images that I'm receiving through props只是我想显示我通过props收到的图像

import Image from "next/image";
import classes from "./book-item.module.css";

export default function FoodItems(props) {
    return (
        <li className={classes.product__item}>
            <Image
                src={props.imageUrl}
                alt={props.title}
                className={classes.image}
                width={100}
                height={100}
            />
            <h3>{props.title}</h3>
            <p>{props.price}</p>
        </li>
    );
}

I'm getting this error from the above code:-我从上面的代码中得到这个错误:-

在此处输入图像描述

Your error clearly states what you are missing ie you need to add allowed domains for images to load from in next.config.js file.您的错误清楚地说明了您缺少的内容,即您需要添加允许的域以便在next.config.js文件中加载图像。

  • Open next.config.js file打开next.config.js文件
  • Add images: { domains: ["itbook.store"], }, add all the domains from where you load images in this array Add images: { domains: ["itbook.store"], },将你加载图像的所有域添加到这个数组中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM