1、下载Word
axios.post('xxxx',params,{responseType: 'blob'}).then(response=>{
let blob = new Blob([response.data],{type: 'application/msword'})
let fileName = '下载结果.docx'
let link = document.createElement('a')
link.download = fileName
link.style.display = 'none'
link.href = window.URL.createObjectURL(blob)
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(link.href)
document.body.removeChild(link)
this.$message.success('下载成功')
}).catch(err=>{
this.$message.error('下载失败')
})
2、下载Excel
axios.post('xxxx',params,{responseType: 'blob'}).then(response=>{
let blob = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
let fileName = '下载结果.xlsx'
let link = document.createElement('a')
link.download = fileName
link.style.display = 'none'
link.href = window.URL.createObjectURL(blob)
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(link.href)
document.body.removeChild(link)
this.$message.success('下载成功')
}).catch(err=>{
this.$message.error('下载失败')
})
3、下载Zip
axios.post('xxxx',params,{responseType: 'blob'}).then(response=>{
let blob = new Blob([response.data],{type: 'application/zip'})
let fileName = '下载结果.zip'
let link = document.createElement('a')
link.download = fileName
link.style.display = 'none'
link.href = window.URL.createObjectURL(blob)
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(link.href)
document.body.removeChild(link)
this.$message.success('下载成功')
}).catch(err=>{
this.$message.error('下载失败')
})