代码片段|前端导出表格

enterBtnClick(date) { let qInfo = {}; //查询参数 let data = https://www.it610.com/article/this.$encryption(qInfo); //加密参数 let url = `/audexport/gzlapi/exportJhgzlData?startDate=${date[0]}&endDate=${date[1]}&statusType=3`; this.$axios .post(url, data, { headers: { //"Content-Type": "application/json; charset=UTF-8" acode: "audreport_other_jslwjhrygz_export" }, responseType: "blob" //二进制流, }) .then(function(res) { if (!res) return; let blob = new Blob([res.data], { type: "application/vnd.ms-excel; charset=utf-8" }); let url = window.URL.createObjectURL(blob); let aLink = document.createElement("a"); aLink.style.display = "none"; aLink.href = https://www.it610.com/article/url; aLink.setAttribute("download", "表名(" + qInfo.startDate + " 至 " + qInfo.endDate + ").xlsx" ); document.body.appendChild(aLink); aLink.click(); document.body.removeChild(aLink); window.URL.revokeObjectURL(url); }) .catch(function(error) { console.log(error.message); }); } }

【代码片段|前端导出表格】加密解密
// 加密 Vue.prototype.$encryption = function (ainfo) { let data = https://www.it610.com/article/Base64.encode(JSON.stringify(ainfo)); data = Base64.encode(data); return data; }// 解密 Vue.prototype.$decryption = function (aresdata) { var resData = Base64.decode(aresdata); try { resData = JSON.parse(resData); } catch (e) { resData = eval("(" + resData + ")"); } return resData }Vue.prototype.openLoading = function () { const loading = this.$loading({// 声明一个loading对象 lock: true,// 是否锁屏 text: '正在加载...',// 加载动画的文字 spinner: 'el-icon-loading',// 引入的loading图标 background: 'rgba(0, 0, 0, 0.3)',// 背景颜色 target: '.analysis',// 需要遮罩的区域 body: true, customClass: 'mask'// 遮罩层新增类名 }) // setTimeout(function () {// 设定定时器,超时5S后自动关闭遮罩层,避免请求失败时,遮罩层一直存在的问题 //loading.close(); // 关闭遮罩层 // }, 20000) return loading; } //关于loding调用 let aloading = ""; //调用时开启 aloading = this.openLoading() //拿到数据时结束 aloading.close()

    推荐阅读