使用img标签时候报路径错误

报错信息

at formatError (file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:50863:46) at TransformContext.error (file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:50857:19) 21:21:33 [vite] Internal server error: Failed to resolve import "src/assets/images/Banner1.jpg" from "src/views/Home/components/Homebanner.vue". Does the file exist? Plugin: vite:import-analysis File: D:/learn/Project/IURunning/iurf/Vue-IURF/src/views/Home/components/Homebanner.vue:4:46 35 | 36 | import { createTextVNode as _createTextVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue" 37 | import _imports_0 from 'src/assets/images/Banner1.jpg' | ^ 38 | import _imports_1 from 'src/assets/images/Banner2.png' 39 | at formatError (file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:50863:46) at TransformContext.error (file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:50857:19) at normalizeUrl (file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:66092:33) at async file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:66247:47 at async Promise.all (index 13) at async TransformContext.transform (file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:66168:13) at async file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite-plugin-inspect/dist/index.mjs:377:17 at async Object.transform (file:///D:/learn/Project/IURunning/iurf/Vue-IURF/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:51172:30) at async

报错原因

<img :src='src\assets\images\Banner1.jpg' alt=""> 如果只用一个 \ 会报错因为这个\已经有特定的含义了

解决办法

使用 转义字符 把\ 转换成\ 。2个\\ = \

所以 加一个\ 就不会报错了 <img :src='src\\assets\\images\\Banner1.jpg' alt="">

相关推荐
heyCHEEMS13 分钟前
记录一下自动化构建中 SSE 与子进程管理的三个坑
javascript·node.js
SonoTommy13 分钟前
在 Node.js 文件上传中集成 ClamAV 扫描
javascript
悟空和大王15 分钟前
内网环境: vue3中使用 iconify 的在线图标
前端
福大大架构师每日一题16 分钟前
openclaw v2026.4.21 更新:图像生成、权限安全、插件修复、Slack 线程、浏览器与 npm 安装全面优化
前端·安全·npm
FanetheDivine16 分钟前
自定义useChat管理AI会话
前端·react.js·aigc
小赵同学WoW21 分钟前
call(), appy(),bind() 之间的区别与使用方法,自己实现这三个函数
前端
Lkstar22 分钟前
读懂 Vue 双端 Diff 算法:从源码到原理,一篇彻底搞懂
vue.js
t***54427 分钟前
如何在 Dev-C++ 中设置 MinGW 和 Clang 的路径
java·前端·c++
拜托啦!狮子30 分钟前
安装EnsDb.Hsapiens.v86
java·服务器·前端
金玉满堂@bj35 分钟前
playwright使用教程总结
前端