616401ea9ccb87f50c67dea59734e189.gif问题:当axios发起post请求,后端返回的是二进制流excel文件,前台获取response时出现乱码问题,求解决方法

41e1ffa98c83cc6cc3218f16f63c30eb.gif

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);

})

},

0c6a989e6dc4adc6f188eb5f41414e90.gif

强行text遇新是直朋能到分览支体调打开还是乱码

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐