vue如何使用excel导出后台数据

  let params = { // 请求参数 要下载Excel的id
    'id':this.excelId
  };
    //导入的接口名
  api_excel_exportExcel().then(res => {
    console.log(res);
    var blob = new Blob([res], {type: 'application/vnd.openxmlformats- officedocument.spreadsheetml.sheet;charset=utf-8'});
    var downloadElement = document.createElement('a');
    var href = window.URL.createObjectURL(blob); //创建下载的链接
    downloadElement.href = href;
    downloadElement.download = 'result.xlsx'; //下载后文件名
    document.body.appendChild(downloadElement);
    downloadElement.click(); //点击下载
    document.body.removeChild(downloadElement); //下载完成移除元素
    window.URL.revokeObjectURL(href); //释放掉blob对象
  }).catch(err => {
    this.$message({
    message:'下载失败!',
    type:'error',
    showClose:true
    })
    })
  }
(0)

相关推荐