reactjs - 我可以将反应道具传递给组件的下一个/图像吗
问题描述
我想要一个使用 next 的 Image 组件的卡片组件。但是,Image 上的 src 道具不接受我传下来的道具。
import React from 'react'
import { Childs } from '../../interfaces/childs'
import Image from 'next/image'
interface CardProps {
img: string
header: string
body: string
}
export default function Card({ img, header, body }: CardProps): JSX.Element {
return (
<div className="
flex items-center justify-center
rounded-lg shadow-lg
bg-blue-200
">
<div className="w-2/5 ">
<Image
src={img}
alt="Picture of the author"
width={"auto"}
height={"auto"}
/>
</div>
<div className=" grid grid-cols-1 w-3/5 ">
<div className="py-4" >
{header}
</div>
<div className="py-4" >
{body}
</div>
</div>
</div>
)
}
错误:无效的 src 属性(https://i1.sndcdn.com/avatars-000422928436-y1ke6o-t500x500.jpg)next/image
,主机名“i1.sndcdn.com”未在您的next.config.js
查看更多信息中的图像下配置:https:/ /err.sh/next.js/next-image-unconfigured-host
解决方案
非常感谢安托瓦内索
添加 root/next.config.js 文件。
//next.config.js
module.exports = {
images: {
domains: ['myimageresources.com'],
},
}
推荐阅读
- tensorflow - 训练具有负概率的神经网络进行回归
- swift - 每当我尝试呈现以前的视图控制器时都会出现阴影
- c++ - NodeMCU 无法让 MQTT 和 Led strip 脚本一起工作
- c# - 在 Windows 10 中使用 CommonOpenFileDialog 选择文件夹但仍显示文件夹中的文件
- mysql - 无法读取未定义节点 js 的属性“查询”
- sql-server - 如何根据参数从存储过程中运行 SQL 语句
- java - 返回的字符串值未显示,JAVA
- node.js - 'string | 类型的参数 字符串[] | 解析问题 | ParsedQs[]' 不可分配给“字符串”类型的参数
- javascript - 如何将带有链接的字符串解析为html链接
- python - 通过检查标志循环