前端请求头 {responseType :‘blob’} 一定要加,是单独一个对象,不能放在请求参数里面

new Blob([res],{type : ‘application/vnd.ms-excel;charset=utf-8’ 一定要设置类型,和后端response.setContentType(“application/vnd.ms-excel;charset=utf-8”)一样

 exportTableAPI: function (params){
      return axios.post('/module/device/export', params,{responseType :'blob'}, {appTitle: "导出表格"}).then(res => res.data);
    }

    //导出数据表
    exportBookingTable(){
      if(!this.checkTableList.length){
        this.$message.warning('请先勾选需要导出表格的行');
        return false;
      }
      let arrId = [];
      for(let item of this.checkTableList){
        arrId.push(item.deviceId);
      }
      api.exportTableAPI({'params':arrId}).then(res=>{
        const url = window.URL.createObjectURL(new Blob([res],{type : 'application/vnd.ms-excel;charset=utf-8'})); 
        const link = document.createElement('a'); 
        link.href = url;
        link.setAttribute('download', '台账列表.xls');
         document.body.appendChild(link); link.click(); 
         document.body.removeChild(link)
         console.log(url);
      })
    },
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐