vue导出Excel

   <el-button size="mini" class="main1_export" @click="EXPORT_RAINDALL()">+导出</el-button>
 //9-导出
            EXPORT_RAINDALL() {
            //element的时间数据转换
                let date1 = new Date(this.input_start);
                let y1 = date1.getFullYear()
                let m1 = date1.getMonth() + 1
                m1 = m1 < 10 ? ('0' + m1) : m1
                let d1 = date1.getDate()
                d1 = d1 < 10 ? ('0' + d1) : d1
                const time1 = y1 + '-' + m1 + '-' + d1
                console.log(time1)

                let date2 = new Date(this.input_end);
                let y2 = date2.getFullYear()
                let m2 = date2.getMonth() + 1
                m2 = m2 < 10 ? ('0' + m2) : m2
                let d2 = date2.getDate()
                d2 = d2 < 10 ? ('0' + d2) : d2
                const time2 = y2 + '-' + m2 + '-' + d2
                console.log(time2)
                if(this.select==="" || this.input_start==="" || this.input_end===""){
                    this.$message("请先进行搜索")
                }
                else {
                    this.axios({
                        method: 'get',
                        params:{
                        //需要传递给后台的数据
                            code:this.select,
                            sdatetime:time1,
                            edatetime:time2,
                            token:this.token,
                        },
                        url:'',
                        headers: {"Authorization": this.token},
                    })
                        .then((res)=>{
                        //关键地方
                        console.log(res.request.responseURL)    //下载网址
                        const downloadElement = document.createElement("a");
                        downloadElement.href = res.request.responseURL;
                        document.body.appendChild(downloadElement);
                        downloadElement.click();
                        document.body.removeChild(downloadElement);
                        })
                        .catch((err)=>{
                            console.log(err)
                        })
                }
            },
上一篇:记一次vue将列表下载为excel的兼容写法


下一篇:axios 请求下载文件