問(wèn)題:當(dāng)axios發(fā)起post請(qǐng)求,后端返回的是二進(jìn)制流excel文件,前臺(tái)獲取response時(shí)出現(xiàn)亂碼問(wèn)題,求解決方法response返回亂碼數(shù)據(jù)。 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 = "對(duì)賬模板"; link.click(); }).catch((e) => { this.$message.warning('下載失敗'); console.log(e); }) },強(qiáng)行text打開(kāi)還是亂碼
vue axios 請(qǐng)求二進(jìn)制流excel文件,response亂碼
慕妹3242003
2019-03-14 18:15:51