做vue后台项目的时候需要post请求向后台提交多数据,方法如下
let url = window.g.ApiUrl + '/file/export/info';
var xhr = new XMLHttpRequest();
xhr.open('post', url, true);
xhr.responseType = 'blob';
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var name = xhr.getResponseHeader('Content-disposition');
var filename = name.substring(20, name.length);
var blob = new Blob([xhr.response]);
let link = document.createElement('a');
let url = URL.createObjectURL(blob);
link.style.display = 'none';
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
}
}
xhr.send(JSON.stringfy(this.selectlist));