// 下载方法
const downloadExcel = (response, name) => {
const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' });
const downloadElement = document.createElement('a');
const href = window.URL.createObjectURL(blob);// 创建下载的链接
downloadElement.href = href;
downloadElement.download = name; // 下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); // 点击下载
document.body.removeChild(downloadElement); // 下载完成移除元素
window.URL.revokeObjectURL(href);
return href;
}
调用方法:
downExcel() {
get('xxx/xxxx/xxxxx请求路径', null, { responseType: 'arraybuffer', }).then(res => {
this.downloadExcel(res, '导入模板.xlsx')
})
},