Last active
April 16, 2020 08:45
-
-
Save Xiaohantx/3b96291ca48d547ca7747b79212069ef to your computer and use it in GitHub Desktop.
文件blob下载
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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