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

发布于:2024-04-19 ⋅ 阅读:(28) ⋅ 点赞:(0)

报错信息

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