vue调接口导出表格

      
 props:{
      form:{
        type:Object,
        default:()=>{}
      },
      indexNum:{
        type:Number,
        default:0
      }
    },
 //导出表格
            handlederive() {
              let _this=this
              let data={
                params:this.form,
                 responseType: 'blob'
              }
    this.axios.get(this.url,data).then(res=>{
       console.log(res)
         if(res.status == 200){
             let blob = res.data;
             const fileReader = new FileReader(); // FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件的内容
             fileReader.readAsDataURL(blob); // 开始读取指定的Blob中的内容。一旦完成,result属性中将包含一个data: URL格式的Base64字符串以表示所读取文件的内容
             fileReader.onload = (event) => { // 处理load事件。该事件在读取操作完成时触发
             console.log(event)
                 // 新建个下载的a标签,完成后移除。
                 let a = document.createElement('a');
                 let _fileName =_this.list[_this.indexNum]+'.csv';
                 a.download = _fileName;
                 a.href = event.target.result; 
                 document.body.appendChild(a);
                 a.click();
                 document.body.removeChild(a);
             }
         }
     })
            },
原文地址:https://www.cnblogs.com/wangjianping123/p/15249950.html