// 下载模板 export function downTemplate(data = {}) { return request({ url: `${apiPrefix}/system/user/importTemplate`, method: 'POST', data, responseType: 'blob' // 需要添加返回类型 }) } const res = await downTemplate() if (res.status === 200) { let blob = new Blob([res.data], { //res.data为返回的文件流 type: 'application/xls;charset=UTF-8' }) let fileName = '导入模板.xls' if ('download' in document.createElement('a')) { // 非IE下载 let a = document.createElement('a') a.download = fileName a.style.display = 'none' a.href = URL.createObjectURL(blob) document.body.appendChild(a) a.click() URL.revokeObjectURL(a.href) // 释放URL 对象 document.body.removeChild(a) } else { // IE10+下载 navigator.msSaveBlob(blob, fileName) } }
标签:二进制,res,前端,fileName,let,blob,document,data,下载 From: https://www.cnblogs.com/LylePark/p/17987383