日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

vue element 导出blob后台文件流xlsx文件自动下载(且规避乱码)

發(fā)布時間:2023/11/27 生活经验 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue element 导出blob后台文件流xlsx文件自动下载(且规避乱码) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

通常情況blob后臺文件流都是如下圖這樣讓人崩潰的亂碼?

?

<el-buttontype="success"@click.stop="handleExport"icon="el-icon-download"
>導(dǎo)出</el-button>
// 導(dǎo)出----------------------------------------
handleExport() {this.loading = true;const data = {// 導(dǎo)出----------------------------------------/*file_name:"推廣記錄(" +new Date().toLocaleString("zh-Hans-CN", {year: "numeric",month: "2-digit",day: "2-digit",hour12: false,hour: "2-digit",minute: "2-digit",second: "2-digit",}).replace(/\//g, "-") +").xlsx",*/// ----------------------------------------gid: this.searchForm.gid,gname: this.searchForm.gname,type: this.searchForm.type,status: this.searchForm.status,num: this.searchForm.num,hy: this.searchForm.hy,remark: this.searchForm.remark,};this.$axios.post("https://xxx.com/getlist?export_flag=1",data,{ responseType: "blob" }).then((d) => {if (!d.data) return (this.loading = false,this.$message.error(d.msg)); //導(dǎo)出失敗報錯!// 自動下載blob文件流xls文件----------------------------------------const blob = new Blob([d.data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",});//防止下載的文件亂碼const url = window.URL.createObjectURL(blob);const link = document.createElement("a");link.style.display = "none";link.href = url;link.setAttribute("download",`導(dǎo)出文件(${new Date().toLocaleString("zh-Hans-CN", {year: "numeric",month: "2-digit",day: "2-digit",hour12: false,hour: "2-digit",minute: "2-digit",second: "2-digit",}).replace(/\//g, "-").replace(/\:/g, "")}).xlsx`//后綴名一定要用xlsx,否則會亂碼); //設(shè)置下載文件名document.body.appendChild(link);link.click();document.body.removeChild(link); // 下載完成移除元素window.URL.revokeObjectURL(url); // 釋放掉blob對象//----------------------------------------this.$message.success("導(dǎo)出xlsx成功");this.loading = false;});
},
// ----------------------------------------

總結(jié)

以上是生活随笔為你收集整理的vue element 导出blob后台文件流xlsx文件自动下载(且规避乱码)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。