1. 程式人生 > >請求二進制流文件,並轉碼下載

請求二進制流文件,並轉碼下載

tex 對象 create || sta ram 標簽 params star

exportExcel () { var str = ‘?‘ for (var i in this.search) { str += i + ‘=‘ + (this.search[i] || ‘‘) } this.loading.start() this.$http({ url: this.exportUrl, method: ‘get‘, params: this.search, responseType: ‘blob‘ //轉碼 }) .then((res) => { const blob = new Blob([res.data], { type: "application/x-xls" }) // 兼容不同瀏覽器的URL對象 const url = window.URL || window.webkitURL || window.moxURL // 創建下載鏈接 const downloadHref = url.createObjectURL(blob) // 創建a標簽並為其添加屬性 let downloadLink = document.createElement(‘a‘) downloadLink.href = downloadHref downloadLink.download = ‘項目回款情況差異表.xls‘; // 觸發點擊事件執行下載 downloadLink.click() }) .finally(() => { this.loading.stop() }) }

請求二進制流文件,並轉碼下載