后端采纳二进制流返回文件而不是罕见的返回收集URL
在antd-pro环境下
发送ajax要求时须要设置为
config = {
headers : {
token : tokenHandler.getSessionByKey('token'),
},
responseType : 'blob',
};
获取到数据以后,在对应modal顶用异步完成下载
* saveFile({ payload: {blob, fileName}}, { call }) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, fileName);
} else {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
//此写法兼容可火狐浏览器
document.body.appendChild(link);
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", false, false);
link.dispatchEvent(evt);
document.body.removeChild(link);
}
},