vue后台管理系统,导出功能

直接上代码

exportData(){
                let urlstr = "/StatisticalAnalysis/exportAreaTargetStatistical"
                if(this.beginTime != "" && this.endTime != ""){
                    urlstr=urlstr+"?b="+this.beginTime+"&e="+this.endTime;
                }
                this.$axios.get(urlstr,{responseType: 'blob'}).then((response) => {
                    console.log(JSON.stringify(response))
                    const blob = new Blob([response.data]); 
                    //const fileName = response.headers['content-disposition'] //下载后文件名
                    const fileName = '区域可疑目标统计.xls';
                    const linkNode = document.createElement('a');
                    linkNode.download = fileName; //a标签的download属性规定下载文件的名称
                    linkNode.style.display = 'none';
                    linkNode.href = URL.createObjectURL(blob); //生成一个Blob URL
                    document.body.appendChild(linkNode);
                    linkNode.click();  //模拟在按钮上的一次鼠标单击

                    URL.revokeObjectURL(linkNode.href); // 释放URL 对象
                    document.body.removeChild(linkNode);
                })
            }

 

posted @ 2020-12-08 11:19  武向前  阅读(510)  评论(0编辑  收藏  举报