问题:在vue 项目中,引入的图片无法在网页显示
控制台报错:图片地址 404 not found
解决方案:
把图片放在 static 文件夹,不要放在 assets 文件夹
index.html 代码:
<img src="./src/assets/img/logo.png" >
解决方案:
1. 把图片放在 static 文件夹,不要放在 assets 文件夹
我在 static 新建一个img 文件夹,并把 assets 文件夹中的图片搬了过去
![]()
2. 重新填写图片路径
<img src="static/img/logo.png" :onerror="defaultImg">
完整 index.html 代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>vue_addname</title> </head> <body> <div id="app"> html网页 内容 <router-link to="/Hello"><img src="static/img/logo.png" :onerror="defaultImg"></router-link> </br> <router-link to="/todolist">Make the to do list</router-link> <router-view></router-view> html网页 内容 </div> <script type="text/javascript"> </script> </body> </html>
图片成功加载