a标签下载zip文件
download () {
this.$axios.post('链接',
{responseType:'blob'})
.then(({data})=>{
let url = window.URL.createObjectURL(new Blob([data],{type: "application/zip"}))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.download='1.zip'// 文件名
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(url)
})
},
非同源下,使用a标签下载,会直接跳转
下载.xls文件
this.$axios.get('链接',{responseType: 'blob'}).then(({data})=>{
let url = window.URL.createObjectURL(new Blob([data],{type:'application/vnd.ms-
excel'}))
window.location.href=url
})
.xlsx : application/vnd.openxmlformats-officedocument.spreadsheetml.sheet