const downExcel=(url=’’,data={},name=‘excel’,method=‘POST’)=>{ //导出
let oReq = new XMLHttpRequest();
oReq.open(method, api+’/’+url, true);
oReq.responseType = “blob”;
oReq.setRequestHeader(“Content-Type”,“application/json”);
oReq.onload = function (oEvent) {
var content = oReq.response;
var elink = document.createElement(‘a’);
elink.download = name+’.xls’;
elink.style.display = ‘none’;
var blob = new Blob([content], { type: ‘application/vnd.ms-excel’})
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
};
oReq.send(JSON.stringify({…data}));
}
调用:
downExcel(){
this.$my.downExcel(‘bms/patientexpress/exportData’,{},‘快递数据’,‘POST’)
},
excel下载导出功能
最新推荐文章于 2024-02-09 00:45:00 发布