JS获取后台返回文件流
export(url, data) {
const xhr = new XMLHttpRequest();
xhr.open(this.requestMethod, url);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.responseType = 'blob';
xhr.onload = function (e) {
const tmpDown = new Blob([this.response]);
const a = document.createElement('a');
a.href = URL.createObjectURL(tmpDown);
a.download = 'export_result.xlsx';
a.click();
};
xhr.send(JSON.stringify(data));
}
网友评论