重点 接口的返回类型设置为 responseType: 'blob',
downLoadFile: (params) => {
return axios.get(`${urls.kaizenEvent.downLoadFile}`, {
params: params,
responseType: 'blob',
});
},
下载方法的实现
重点 将返回的二进制文件流转为blob 去接受
link.download = item.fileName; 文件名可以自己设置 也可以根据接口返回的内容显示
this.$api.kaizenEvent
.downLoadFile(params)
.then((res) => {
console.log(841, res);
let blob = new Blob([res.data], {
type: 'application/vnd.ms-excel;charset=UTF-8',
});
console.log(847, blob);
if (window.navigator.msSaveOrOpenBlob) {
//兼容 IE & EDGE
navigator.msSaveBlob(blob);
} else {
var link = document.createElement('a');
// 兼容不同浏览器的URL对象
const url = window.URL ||