vue 下载

import { downloadFile } from ‘@/api/workBench/qrcode.js’;

downloadFile(item) {
console.log(item)
let downloads = item.response.data[0].fileId
let downloadLoadingInstance = Loading.service({
text: “正在下载数据,请稍候”,
spinner: “el-icon-loading”,
background: “rgba(0, 0, 0, 0.7)”,
});
downloadFile({ fileId: downloads }).then(res=>{
if( res.code == 500 ){
downloadLoadingInstance.close();
return;
}
// 创建一个URL对象
let url = window.URL.createObjectURL(res);
// // 创建一个a标签
let a = document.createElement(“a”);
a.href = url;
a.download = item.response.data[0].realName;// 这里指定下载文件的文件名
a.click();
downloadLoadingInstance.close();
}).catch(err=>{
downloadLoadingInstance.close();
})
},

qrcode.js
export function downloadFile(query) {
return request({
url: ‘doc/downloadAttachmentFileNoVerify/’ + query.fileId,
method: ‘get’,
responseType : ‘blob’,
params: query
})
}

你可能感兴趣的:(vue.js,javascript,前端)