axios设置返回格式为arraybuffer 或者 blob(最佳 不会乱码)
例如:
this.$axios({
method: 'post',
header: {'Content-Type': 'application/xls'}, // http请求类型
responseType: 'blob', // 返回格式,默认json,可选arraybuffer、blob、document、json、text、stream
url: url,
data: data
})
.then( res =>{
//application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型
let blob = new Blob([res.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'});
let downloadElement = document.createElement('a');
let href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = '反馈消息表.xls'; // xxx.xls/xxx.xlsx
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href);
})