vue利用后台返回二进制文件流做个表格
// 导出报表接收url 、参数 返回二进制文件流export function exportExcel(url, data) {return new Promise(resolve => {request({url: url,method: 'post',responseType: 'blob',data...
·
// 导出报表 接收url 、参数 返回二进制文件流
export function exportExcel(url, data) {
return new Promise(resolve => {
request({
url: url,
method: 'post',
responseType: 'blob',
data
}).then(res => {
//str是后台返回的文件名称 放在了response header里
let str = res.headers['content-disposition'];
let fileName = decodeURI(str.substr(str.indexOf('%')))
let blob = new Blob([res.data], {
type:
"application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
});
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob);
} else {
let elink = document.createElement("a");
elink.download = fileName;
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
}
resolve('导出报表成功!')
})
})
}
更多推荐
已为社区贡献12条内容
所有评论(0)