vue請求後端下載excel文件

this.$axios.get(this.$store.state.api+"/api/excelData/"+this.id+"?startTime="+this.selectTime[0]+"&endTime="+this.selectTime[1],{headers:{'Authorization':'Bearer '+this.userInfo.access_token},responseType:'blob'})

                .then((res)=>{

                    if(res.status == "200") {

                        const aLink = document.createElement("a");

                        let blob = new Blob([res.data], {type: "application/vnd.ms-excel;charset=utf-8"})

                        aLink.href = URL.createObjectURL(blob)

                        aLink.download = 'test.xls'

                        aLink.click()

                        document.body.appendChild(aLink)

                    }

                }).catch(function (error){

                    console.log('error') 

                });

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章