Skip to content

Instantly share code, notes, and snippets.

@Xiaohantx

Xiaohantx/down-file.js

Last active Apr 16, 2020
Embed
What would you like to do?
文件blob下载
const blob = new Blob([res.data], {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
// 文件格式
})
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = 'markone'
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else { // IE10+下载
navigator.msSaveBlob(blob, 'markone')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.