下载blob
export async function downloadFile(fileName: string, resBlob: Blob) {
const canDownload = await fileCanDownload(resBlob)
if (!canDownload) return
const blob = new Blob([resBlob])
if ('download' in document.createElement('a')) {
// 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else {
// IE10+下载
(navigator as any).msSaveBlob(blob, fileName)
}
}
base64 下载
export function downloadFileBase64(fileName: string, base64: string) {
if ('download' in document.createElement('a')) {
// 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = base64
document.body.appendChild(elink)
elink.click()
document.body.removeChild(elink)
}
}
自己项目用到,保存一下,有能用得到的自行修改哦