image - 在 Next.js 中导入本地图像时遇到问题
问题描述
我正在尝试导入保存在我的 next.js 项目的公用文件夹中的本地图像。最终目标是导入本地图像,将该图像保存在对象数组中,最后映射到数组并生成一组卡片。我以前用 React 做过这种方式。我使用了 SVGOMG 并将清理代码转换为 jsx ..
import Icon from "../public/assets/undraw_barbecue_3x93.svg";
const DUMMY_CHARACTERISTICS = [
{
id: "card1",
image: Icon,
title: "Insert text here",
description: "Insert text here",
},
const Characteristics = () => {
return (
<ul>
{DUMMY_CHARACTERISTICS.map((item) => (
<CharacteristicsCard
key={item.id}
id={item.id}
image={item.image}
title={item.title}
description={item.description}
/>
))}
</ul>
);
};
const CharacteristicsCard = (props) => {
return (
<li id={props.id}>
<Image src={props.image} width={150} height={150} />
<h1>{props.title}</h1>
<p>{props.description}</p>
</li>
);
};
Error Message: Can't resolve file path to image
解决方案
推荐阅读
- python - 如何删除使用旧版本 Python/Pip 安装的软件包?
- java - 验证扫描仪输入时出错,包含两个带一个空格的单词
- r - R中用于返回正则表达式中匹配的单词数的语法是什么?
- node.js - 该脚本在终端中运行,但不适用于 js exec()
- sprite - 从头精灵没有一致地记录命中
- javascript - 我想做一些操作并根据我在另一个 AOB 中得到的结果创建新的对象数组
- mysql - 请帮我列出每个社区最喜欢和评论最多的前 2 个故事
- shell - Uniq 一列并打印出该列中的行数
- spring-boot - 如何测试 Spring Boot 应用程序每天早上在特定时间运行的 cron 作业?
- java - 为什么我们有两种方法可以在 android 的视图上添加事件监听器?