前端下载后端接口资源 blob下载

前端通过接post接口访问下载资源文件zip格式的前端下载后端接口资源 blob下载 export:function(layerIndex){
const req = new XMLHttpRequest();
req.open(‘POST’, ‘…/assessmenttablerecords/export’, true);
req.responseType = ‘blob’;
req.setRequestHeader(‘Content-Type’, ‘application/json’);
req.onload = function() {
var filename = ‘文件.zip’
const content = req.response;
const blob = new Blob([content],{type:“application/zip”})
const blobUrl = window.URL.createObjectURL(blob);
vm.download(blobUrl,filename) ;
layer.close(layerIndex);
};
req.send(JSON.stringify(vm.exportId));
},
download:function(blobUrl, filename) {
const a = document.createElement(‘a’);
a.style.display = ‘none’;
a.download = filename;
a.href = blobUrl;
a.click();
$(a).remove();
},