const url = '/sasd/fsd/xxxx/exportMailData2Excel'
this.downloadFile(url, 'blob', this.isSearch) // 調用 方法; post 方式;也可以改為 get
// 下載文件方法 downloadFile (url, resType, para) { this.$http.post(url, para, { responseType: resType // responseType:'arraybuffer', //可以開啟不同傳輸模式 字節兼容 }) .then((res) => { const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' }) const downloadElement = document.createElement('a') // 創建下載的鏈接 const href = window.URL.createObjectURL(blob) downloadElement.href = href downloadElement.download = '異地社保卡郵寄.xls' // 下載后的文件名 document.body.appendChild(downloadElement) downloadElement.click() // 下載 document.body.removeChild(downloadElement) // 下載完成 移除 a window.URL.revokeObjectURL(href) // 釋放blob對象 }) },
window.open(url) get 請求 導出文件
