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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM