function downloadFile(url) {
console.log(url)
const link = document.createElement('a')
fetch(url).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
console.log(blob)
link.href = URL.createObjectURL(blob)
// console.log(link.href)
link.download = ''
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
}
js实现a标签点击下载图片和txt等文件,而不是浏览器打开预览
猜你喜欢
转载自blog.csdn.net/weixin_46408500/article/details/128798676
今日推荐
周排行