reactjs - Next.js 无法在运行时提供动态图像
问题描述
因此,我将 Next.js API 用于我的项目后端,并将 Mongodb 用于数据库。我必须提供用户在运行时上传的图像。由于这些文件在构建期间尚不可用,因此它们不会被识别为可以存储在public
目录中的静态文件。
我已经尝试过next-images
next.config.js
,并在我的代码中添加了一些配置:<img src={require(
../../../images/${picture.src})} alt={picture.legend} />
。
我也尝试过使用文件加载器,但仍然没有运气。
我错过了什么?
感谢您的回复!
解决方案
过去在加载图像和/或字体时遇到这些问题时,此配置对我有用:
npm install url-loader --save-dev
next.config.js
module.exports = {
webpack: function (config) {
config.module.rules.push({
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]',
},
},
});
return config;
},
}
推荐阅读
- c# - 程序中途未处理的长度异常
- python - 数组的地址与数组[0]的地址 - Python
- c++ - 有人可以解释这个指针在这里指的是什么吗?
- excel - Excel VBA 使用标准提交所有记录
- python - 字符串匹配与python中的字典键
- javascript - 如何在 bootstrap 4 中为 col 调整大小设置动画?
- delphi - 在 delphi 中创建一个 TStringGrid 类,其中与单元格关联的对象数组被指定为更具体的类型
- batch-file - 从批处理文件中的“runas”执行“takeown”命令时出错
- sql - 修剪后的 SQL 计数行数
- devops - 将 OpenAm 配置为使用另一个服务进行身份验证的中间身份验证 REST 服务