处理blob文件下载抛出json格式异常的问题 #144
Anuluca Date : 2022-03-31 Tags : 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| let that = this axios.get({ url: 'xxxxxx', method: 'get', data:{}, responseType: 'blob', }).then(res => { let reader = new FileReader(); reader.readAsText(res) reader.onload = function (result) { try { let resData = JSON.parse(result.target.result); if (resData.code) { that.$message({ type: 'error', message: resData.desc }) } } catch (err) { let blob = new Blob([res], {type: "application/vnd.ms-excel"}); var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = `文件名.xls`; link.click() } }; })
|