1.使用官方引用静态资源处理,需要把图片放在public里面
getImageUrl(name) { return new URL(`./img/${name}.png`, import.meta.url).href }
2.本地运行项目中可以显示图片,但是发布后报Failed to construct ‘URL’: Invalid URL错误,是因为把 esbuild 构建目标设置为 es2020 或更高版本
import vue from "@vitejs/plugin-vue"; export default { base: "/", plugins: [vue()], optimizeDeps: { include: ["schart.js"], }, build: { target: "es2020", }, optimizedeps: { esbuildoptions: { target: "es2020", }, }, };
标签:vue,URL,es2020,Invalid,Failed,construct,vue3 From: https://www.cnblogs.com/angel648/p/16631049.html