1、第一種 (本地生效了,線上不生效)
<el-image :src="getImgSrc(item.name)"></el-image>
const getImgSrc = (name) => {
const url = `../../assets/images/file/icon_${getFileImg(name)}.png`
return new URL(url, import.meta.url).href
}
// 生產(chǎn)構(gòu)建時(shí),URL字符串必須是靜態(tài)敌厘,才能分析,轉(zhuǎn)換成打包哈希的地址
2朽合、第二種 (本地俱两、線上都OK)
import defaultImg from '@/assets/images/file/icon_default.png'
import pptImg from '@/assets/images/file/icon_ppt.png'
import excelImg from '@/assets/images/file/icon_excel.png'
import wordImg from '@/assets/images/file/icon_word.png'
import compressImg from '@/assets/images/file/icon_compress.png'
import pdfImg from '@/assets/images/file/icon_pdf.png'
const getImgSrc = (name) => {
name = getFileImg(name)
return {
'ppt': pptImg,
'excel': excelImg,
'word': wordImg,
'compress': compressImg,
'pdf': pdfImg,
'default': defaultImg
}[name] || defaultImg
}