web-utils-super
Version:
前端函数库
25 lines (23 loc) • 686 B
JavaScript
/**
* @desc: 下载文件 excel word
* @param {String} fileName 文件名
* @param {String} fileType 文件类型 可选值:excel | word
* @param {File | Blob} data 二进制流
*/
function downloadFile(fileName, fileType, data) {
const aLink = document.createElement("a");
let type = "";
if (fileType === "excel") {
type = "application/vnd.ms-excel";
} else if (fileType === "word") {
type = "application/msword";
} else return
const blob = new Blob([data], {
type,
});
aLink.href = URL.createObjectURL(blob);
aLink.download = fileName;
aLink.click();
document.body.appendChild(aLink);
}
module.exports = downloadFile;