export function downloadExcel(obj) { return request({ url: '/basic/cycleMoneyReport/downloadExcel', method: 'post', data: obj, // 请求方式必须添加 responseType 相应方式 responseType: 'blob' }) }
/** * 从response读取流下载 * @param response 响应体 * @param suffix 文件后缀名 */ export function downloadBlob(res,name){ console.log(res) let blob = new Blob([res.data], {type: 'data:application/vnd.ms-excel;base64;charset=utf-8'}); let downloadElement = document.createElement('a'); let href = window.URL.createObjectURL(blob); //创建下载的链接 downloadElement.href = href; downloadElement.download = name+'.xlsx'; //下载后文件名 document.body.appendChild(downloadElement); downloadElement.click(); //点击下载 document.body.removeChild(downloadElement); //下载完成移除元素 window.URL.revokeObjectURL(href); //释放掉blob对象 return true }
downloadExcel({ year: this.year, month: this.paramDate, type: this.typeValue }).then(response => { downloadBlob(response,"报表") })
标签:vue,res,href,blob,downloadElement,excle,response,下载 From: https://www.cnblogs.com/chenTo/p/17934990.html