const downLoadFunc = (imgSrc, imgName) => {
if (!imgSrc) return
const fileExt = imgSrc.split('.').pop().toLocaleLowerCase()
if (fileExt == 'pdf') {
fetch(imgSrc).then(function (response) {
response.arrayBuffer().then(res => {
let type = 'application/pdf;charset-UTF-8' // 资源类型
let blob = new Blob([res], {type: type})
let objectUrl = URL.createObjectURL(blob)
let link = document.createElement('a')
link.style.display = 'none'
link.href = objectUrl
link.setAttribute('download', imgName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
})
}
}
网友评论