下载文件前端一般是两个方式下载
1:get下载
利用window.open来下载数据
优点:简单易操作;
缺点:因为get无法设置请求头,所以一般的身份信息就不能在请求头里带了,要么就是get的路径里加上身份信息,方便记录日志。
不是很推荐
window.open( res.data);
2:前端流下载
生成blob流的方式来下载文件,比较推荐的方式
下面是项目里写的一个方法
// 导出列表 1pdf 2word 3html
exReport(type: number) {
this.reportBody.doctype = type;
type === 1 ? this.pdfLoading = true : type === 2 ? this.wordLoading = true : this.htmlLoading = true;
const url = type === 1 ? this