const downloadRes = async (url, name) => {
let response = await fetch(url)
// 内容转变成blob地址
let blob = await response.blob()
// 创建隐藏的可下载链接
let objectUrl = window.URL.createObjectURL(blob)
let a = document.createElement('a')
//地址
a.href = objectUrl
//修改文件名
a.download = name
// 触发点击
document.body.appendChild(a)
a.click()
//移除
setTimeout(() => document.body.removeChild(a), 1000)
}
let url = 'https://pics4.baidu.com/feed/241f95cad1c8a7869584e9de81872b3472cf50c8.jpeg?token=4c44645e8c72bc8e0e0fcac40cd27e77'
downloadRes(url,'名称')
H5下载文件跨域问题解决方案
最新推荐文章于 2024-05-15 09:52:22 发布