原因有2:
第一引用mock导致,
第二下载时需要设置请求 responseType: ‘blob’
下载代码如下:
export async function DownLoadFile(params) {
return request(File_DownLoad,METHOD.GET, params,{responseType: 'blob'})
}
download: function (fileId, fileName) {
console.log("++++" + fileId);
var reqcondition = { file_Id: fileId };
DownLoadFile(reqcondition).then((res) => {
console.log(res);
console.log(fileName);
this.Pagedownload(res.data, fileName);
});
},
Pagedownload(data, fileName) {
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", fileName);
document.body.appendChild(link);
link.click();
},