vue ajax二进制文件乱码,vue axios 请求二进制流excel文件,response乱码
问题:当axios发起post请求,后端返回的是二进制流excel文件,前台获取response时出现乱码问题,求解决方法response返回乱码数据。downloadModel(){// window.location.href = window.open(axios.defaults.baseURL +'/settlement/payableCheck/download/template');
问题:当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遇新是直朋能到分览支体调打开还是乱码
更多推荐
所有评论(0)