vue下载zip包到本地

<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文件

posted @ 2021-04-28 11:09  bud  阅读(2491)  评论(0)    收藏  举报