问题:当axios发起post请求,后端返回的是二进制流excel文件,前台获取response时出现乱码问题,求解决方法response返回乱码数据。 downloadModel(){ // window.location.href = window.open(axios.defaults.baseURL +'/settlement/payableCheck/download/template'); // let downLoadModel = window.open(); // let fileDownload = require('js-file-download'); this.$post('/settlement/payableCheck/download/template',{params:null},{responseType: 'arraybuffer'}).then(res => { // this.$get('/settlement/payableCheck/download/template').then(res => { console.log(res); // let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0]; // fileDownload(res,fileName); let blob = new Blob([res], {type: "application/vnd.ms-excel;charset=utf-8"}); // let objectUrl = URL.createObjectURL(blob); // window.location.href = objectUrl; var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = "对账模板"; link.click(); }).catch((e) => { this.$message.warning('下载失败'); console.log(e); }) },强行text打开还是乱码
5 回答

米琪卡哇伊
TA贡献1998条经验 获得超6个赞
responseType: 'blob' blob 设置这个类型呢? {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"} ,还有 别用编辑打开excel啊
添加回答
举报
0/150
提交
取消