vue 后台返回的文件流进行预览_vue前端接收后端接口文件流application/octet-stream转为excel并弹出下载...
我们在做前后端对接时,经常会遇到要做图表导出的功能,这里分享一个前端接收ArrayBuffer转为Blob并下载为excel的代码段,兼容IE、Chrome、FirefoxexportconstdownLoadXls=(fileArrayBuffer,filename)=>{letdata=newBlob([fileArrayBuffer],{type:'appl...
我们在做前后端对接时,经常会遇到要做图表导出的功能,这里分享一个前端接收ArrayBuffer转为Blob并下载为excel的代码段,兼容IE、Chrome、Firefoxexport const downLoadXls = (fileArrayBuffer, filename) => {
let data = new Blob([fileArrayBuffer], { type: 'application/vnd.ms-excel,charset=utf-8' });
if (typeof window.chrome !== 'undefined') {
// Chrome
var link = document.createElement('a');
link.href = window.URL.createObjectURL(data);
link.download = filename;
link.click();
} else if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE
var blob = new Blob([data], { type: 'application/force-download' });
window.navigator.msSaveBlob(blob, filename);
} else {
// Firefox
var file = new File([data], filename, { type: 'application/force-download' });
window.open(URL.createObjectURL(file));
}
}
本文为胖虎原创文章,转载无需和我联系,但请注明来自胖虎博客panghucat.cn上一篇:没有了
更多推荐
所有评论(0)