关于后台返回文档流的文件下载
<template>
<i @click="downLoad(data)" class="downLoad">下载</i>
</template>
//下载
downLoad(val) {
let url = val.httpUrl
let fileTye = url.match(/.+\/(.+)$/)[1];
let that = this;
let formData = new FormData();
formData.append('fileUrl',url);
this.$http({
url:api.archivesLoadFile,
method:'POST',
headers:headers('multipart/form-data'),
responseType: 'blob',
data: formData,
}).then(function (res) {
let result=res.data;
let url = window.URL.createObjectURL(new Blob([result]));//处理文档流
let link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.download = fileTye;
document.body.appendChild(link);
link.click();
}).catch(function (error) {
that.$message.error(error);
});
},