Skip to content

Instantly share code, notes, and snippets.

@Xiaohantx
Last active April 16, 2020 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xiaohantx/3b96291ca48d547ca7747b79212069ef to your computer and use it in GitHub Desktop.
Save Xiaohantx/3b96291ca48d547ca7747b79212069ef to your computer and use it in GitHub Desktop.
文件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