新建utils里面index
里面配置
export const getImageURL = img => {
return new URL(`../assets/img/${img}`, import.meta.url).href
}
页面使用
import { getImageURL } from "@/utils"
<img :src="getImageURL('install/icon1.png')" alt="">
这里是其他配置
'@': new URL('src', import.meta.url).pathname,
'@img': new URL('src/assets/img', import.meta.url).pathname,