api中添加 responseType: 'blob'
export async function export(params) {
return await request.get('/aaa/export', { params, responseType: 'blob' });
}
<a-button @click='exportHandle'>导出</a-button>
// 导出事件
const exportHandle = () => {
let request = {
id:'12223'
};
exportList(request).then(res => {
const blob = new Blob([res], { type: 'application/vnd.ms-excel;charset=utf-8' });
const link = document.createElement('a'); // 创建a标签
link.href = window.URL.createObjectURL(blob);
link.download = '嘉宾名单';
link.click(); //点击下载
// 释放URL对象
window.URL.revokeObjectURL(link.href);
});
};
vue实现下载后端返回Excel文件流
最新推荐文章于 2024-05-16 13:30:42 发布