利用表单提交方式,
downloadFile(url, method, params) {
if (!document.getElementById("myIframe")) {
let iframe = document.createElement('iframe');
iframe.id = "myIframe";
iframe.name = "myIframe";
iframe.style = "display:none";
document.body.appendChild(iframe);
}
let form = document.createElement('form');
form.target = "myIframe";
document.body.appendChild(form);
for (let obj in params) {
if (Object.prototype.hasOwnProperty.call(params, obj)) {
let input = document.createElement('input');
input.tpye = 'hidden';
input.name = obj;
input.value = params[obj];
form.appendChild(input);
}
}
form.method = method == null ? "GET" : method;
form.action = url;
form.submit();
document.body.removeChild(form);
}