1
<img :src="getImage()" alt="">
const getImage = () => {
return new URL(`../../assets/1.png`, import.meta.url).href;
}
2
<img :src="img" alt="">
import img from "@/assets/2.png";
本文展示了如何在JavaScript中通过`import.meta.url`获取相对路径,并动态导入图片资源。首先使用`newURL()`构造函数,然后导入@/assets/2.png的图片。
1
<img :src="getImage()" alt="">
const getImage = () => {
return new URL(`../../assets/1.png`, import.meta.url).href;
}
2
<img :src="img" alt="">
import img from "@/assets/2.png";
1059
7281
1241

被折叠的 条评论
为什么被折叠?