1. 程式人生 > 實用技巧 >vue如何使用excel匯出後臺資料

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     })    })   }