一、使用axios请求后台接口
this.$http({
url:'请求地址',
method: 'post',
responseType:'blob',
data: data,
}).then(res => {
this.downloadFile(res.data)
})
二、下载
downloadFile(data) {
// 文件导出
if (!data) {
return
}
let url = window.URL.createObjectURL(new Blob([data]));
let link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute('download', '测试excel.xls');
document.body.appendChild(link);
link.click()
},