分享一个BuildAdmin用到的图片预览功能
<el-image
:preview-src-list="[state.showCompanyDetail.business_license]"
:src="previewRenderFormatterImg(state.showCompanyDetail.business_license)"
alt="Business License"
class="business-license"
>
</el-image>
web/src/views/backend/routine/attachment/index.ts
export const previewRenderFormatterImg = (row: string) => {
const cellValue = row.substring(row.lastIndexOf(".") + 1);
const imgSuffix = ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'webp']
if (imgSuffix.includes(cellValue)) {
return row
}
return buildSuffixSvgUrl(cellValue)
}
url给到:http://localhost:8000/storage/default/20240129/xxxx.jpg