前端下载视频或pdf等文件
文章目录
const req = new XMLHttpRequest()
req.open('GET','/xxx/xxx', true)
req.responseType = 'blob'
req.setRequestHeader('Content-Type', 'application/json')
req.onload = function () {
const data = req.response
const blob = new Blob([data])
const blobUrl = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.style.display = 'none'
a.download = 'aaa.pdf'
a.href = blobUrl
a.click()
}
req.send()
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论