前后分离后
export const download = function(options){
let xhr = new XMLHttpRequest(); // XMLHttpRequest 对象xhr.open("GET", options.url, true); xhr.setRequestHeader('Authorization', authorization());//前后分离的权限头xhr.send(obj2url(options.get)); xhr.responseType = "blob";//这里是关键,它指明返回的数据的类型是二进制xhr.onreadystatechange = function(e) { if (this.readyState == 4 && this.status == 200) { console.log('change download'); var response = xhr.response; let url = URL.createObjectURL(response); img.src=url;//如果这里是图片,可以显示出图片。 window.open(url);//想通过打开窗口来下载excel文件。却不可以。 } }
};
想通过download({url:"http://xxx.ssss:88/sss.xls"});来下载服务器的excel文件。
相关分类