使用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="">

相关推荐
这里有鱼汤20 分钟前
Python 的 bisect 模块:这个冷门宝藏你用对了吗?
前端·后端·python
博览鸿蒙21 分钟前
FPGA设计职位介绍|如何成为一名合格的数字前端设计工程师?
前端·fpga开发
老胡说前端22 分钟前
JS 数组相同的key 进行合并
前端·javascript·vue.js
S01d13r25 分钟前
LeetCode 解题思路 33(Hot 100)
javascript·算法·leetcode
kovlistudio30 分钟前
红宝书第三十二讲:零基础学会模块打包器:Webpack、Parcel、Rollup
前端·javascript·webpack·node.js
天天进步201532 分钟前
Java全栈项目--校园快递管理与配送系统(5)
java·javascript·vue.js
这里有鱼汤32 分钟前
Python 跨平台路径处理:最优解来了!
前端·后端·python
SailingCoder34 分钟前
npm ERR! CXX(target) Release/obj.target/deasync/src/deasync.o
前端·npm·node.js
念九_ysl1 小时前
使用 Vue 快速集成 FullCalendar 日历组件教程
前端·javascript·vue.js
造夢先森1 小时前
SpringAI+MCP协议 实战
前端·javascript·easyui