axios({
method: 'post',
headers: {'content-type': 'application/JSON;charset=UTF-8'},//一定要问清后端是什么我的是json还有的是application/x-www-form-urlencoded
url: ``,//接口地址
data: {
ids:this.ArrId//参数,我的是选中列表的id
},
responseType: 'blob', //responseType类型,不写的话会是乱码
}).then(res => {
let blob = new Blob([res.data])
if('download' in document.createElement('a')){
let link = document.createElement('a')
link.download='ss'+'.xlsx' //文件名
link.style.display;
link.href = URL.createObjectURL(blob)
document.body.appendChild(link)
link.click()
URL.revokeObjectURL(link.href)
document.body.appendChild(link)
}else if('msSaveOrOpenBlob' in Navigator){
window.navigator.msSaveOrOpenBlob(blob,'ss'+'.xlsx')
}else {
alert('失败')
}
})
axios POST请求导出Excel
最新推荐文章于 2024-05-16 10:52:34 发布