之前导出通过location.href 直接进行导出 ;
直接 调用接口 页面静止时间过长,需要增加loading优化用户体验
项目中用的是axios和iview框架 。
const headers = {
responseType:'blob'
}
this.$Spin.show();
this.$http.get(url,headers).then(function(data){
if(data.status == 200){
this.$Spin.hide();
var blob = data.data;
let reader = new FileReader();
let _this = this;
reader.readAsDataURL(blob);
reader.onload = e=>{
var a = document.createElement('a');
let time = this.$common.dateTime(new Date().getTime(),4);
a.download = `xxx${time}.xlsx`;
a.href = e.target.result;
$("body").append(a); // 修复firefox中无法触发click
a.click();
window.URL.revokeObjectURL(a.href);
$(a).remove();
_this.$refs.selection.selectAll(false)
}
}
})