<script>
import axios from 'axios'
export default{
methods: {
downloadZip (downloadName, downloadPath) {
axios.get('/downloadZip', { downloadPath: downloadPath }).then((res) => {
if (res.status === 200){
const blob = new Blob([res.data], { type: 'application/zip'})
if ('download' in document.createElement('a')){
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = downloadName
link.click()
// 釋放內存
URL.revokeObjectURL(url)
} else {
// ie10下載
navigator.msSaveOrOpenBlob(blob, downloadName)
}
}
})
},
}
}
</script>
參考:vue blob流下載zip文件_Thekingyu的博客-CSDN博客_vue下載zip文件