vue.js中使用axios发送post请求实现excel下载
1. 前端:this.axios({ method: 'post', responseType: 'blob', url: 'testUrl', data: {'id': id}}).then(res => { let fileName = res.headers['content-disposition'].split(';')[1].split...
1. 前端:
this.axios({
method: 'post',
responseType: 'blob',
url: 'testUrl',
data: {'id': id}
}).then(res => {
let fileName = res.headers['content-disposition'].split(';')[1].split('=')[1].replace(/\"/g,'')
let type = res.headers['content-type']
let blob = new Blob([res.data], {type: type})
// IE
if (window.navigator.msSaveBlob){
window.navigator.msSaveBlob(blob, fileName)
}
})
2. 后端:(仅response设置部分)
String headString = "attachment; filename=\"" + new String("testUrl".getBytes("gb2312"), "ISO8859-1") + "\"";
response.setContentType("octets/stream");
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", headString);
out = response.getOutputStream();
更多推荐
所有评论(0)