0
点赞
收藏
分享

微信扫一扫

Vue利用文件流下载Excel文件

蓝哆啦呀 2022-03-15 阅读 179

在get和post下载的时候地址的封装都一不一样

let params={
       regionCode: that.$refs.regioncode1.regioncode,
       stationName: that.searchCondition_form.key,
       monitorTypeId: that.searchCondition_form.type,
       status: that.searchCondition_form.status,
       limit: that.pagesize,
       page: that.pagenum
      }
      that.axios.post("http://192.168.1.234:7772/monitor-station/get-stations-by-region-excel",
          params,{
        responseType: 'arraybuffer',
        headers: {'token': that.$store.state.auth.user.token}})
          .then((response) => {
            let blob = new Blob([response.data],{type:'application/vnd.ms-excel;charset=utf-8'})
            let downloadElement = document.createElement('a');
            let href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            downloadElement.download = '监测站点.xlsx'; //下载后文件名
            document.body.appendChild(downloadElement);
            downloadElement.click(); //点击下载
            document.body.removeChild(downloadElement); //下载完成移除元素
            window.URL.revokeObjectURL(href); //释放掉blob对象
          })
          .catch(() => {
          });
举报

相关推荐

0 条评论