api.js
// 数据统计 导出
export const exportExcelUserVideoData = data => {
return service({
url: '/data/exportExcelUserVideoData',
method: 'post',
data,
responseType: "arraybuffer"//请求里添加这行
})
};
view页面的请求
async exportExcelUserVideoData() {
if (this.checkList1+'' != "") {
let data = {
date: this.dd,
channel: this.checkList1 + ""
};
let res = await exportExcelUserVideoData(data);//请求的方法
//以下是处理文件流的代码 [res]:[res是上方的请求到的文件流]
let blob = new Blob([res], { type: "application/vnd.ms-excel" });
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, `数据统计表${this.dd}.xls`);
} else {
let downloadElement = document.createElement('a');
let href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
downloadElement.download = `数据统计表${this.dd}.xls`; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
}
}
网友评论