27 lines
721 B
JavaScript
27 lines
721 B
JavaScript
|
|
// 下载blob文件
|
||
|
|
export const downloadFile = ({ fileData, fileType, fileName }) => {
|
||
|
|
const blob = new Blob([fileData], {
|
||
|
|
type: fileType
|
||
|
|
})
|
||
|
|
const link = document.createElement('a')
|
||
|
|
link.href = URL.createObjectURL(blob)
|
||
|
|
link.download = fileName
|
||
|
|
link.style.display = 'none'
|
||
|
|
document.body.appendChild(link)
|
||
|
|
link.click()
|
||
|
|
URL.revokeObjectURL(link.href)
|
||
|
|
document.body.removeChild(link)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 通用a链接下载
|
||
|
|
export const downloadFileByUrl = (url) => {
|
||
|
|
const link = document.createElement('a')
|
||
|
|
link.href = url
|
||
|
|
link.setAttribute('download', '')
|
||
|
|
link.style.display = 'none'
|
||
|
|
document.body.appendChild(link)
|
||
|
|
link.click()
|
||
|
|
URL.revokeObjectURL(link.href)
|
||
|
|
document.body.removeChild(link)
|
||
|
|
}
|