vue下载excel流文件
this.$http.post(errUrl, [], {responseType: 'blob'}).then(res => {const content = res.dataconst blob = new Blob([content], {type: "application/...
·
this.$http
.post(url,{},{
responseType: 'blob'
})
.then(res => {
let content = res.data
let blob = new Blob([content], {
type: "application/vnd.ms-excel;charset=utf-8"
});
let elink = document.createElement('a')
// 非IE下载
if ('download' in elink ) {
elink.download = "XXX" // 文件名字
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href)
document.body.removeChild(elink)
}
// IE10+下载
else {
navigator.msSaveBlob(blob, fileName)
}
})
.catch(err => {
console.log(err);
})
注意:不加响应类型会乱码
{
responseType: 'blob'
}
更多推荐
已为社区贡献2条内容
所有评论(0)