您当前的位置: 首页 > 

Dream丶Killer

暂无认证

  • 0浏览

    0关注

    188博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

超有效的解決方案:Failed to load resource: the server responded with a status of 404 (Not Found)

Dream丶Killer 发布时间:2021-05-03 20:07:18 ,浏览量:0

Failed to load resource: the server responded with a status of 404 (Not Found) 问题描述:

nextjs项目里想要引入图片,地址都是对的,但是最后报404错误

解决办法:

1、在项目根目录添加一个static文件夹,在static中创建一个images文件夹,将图片放在images文件夹中。

2、引入方式


3、安装url-loader

yarn add url-loader

4、在next.config.js文件写入相应配置

module.exports = {
    webpack: (config) => {
        config.module.rules.push({
            test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
            loader: require.resolve("url-loader"),
            options: {
              limit: 10000,
              name: "static/media/[name].[hash:8].[ext]",
            },
        
        });
        return config;
    }
}
❤运行项目,图片引入成功!开森~❤

在这里插入图片描述

关注
打赏
1655344294
查看更多评论
立即登录/注册

微信扫码登录

0.0367s