let params = { // 請求參數 要下載Excel的id 'id':this.excelId }; //導入的介面名 api_excel_exportExcel().then(res => { console.log(res); var blob = new Blob([res], {t ...
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 }) }) }