vue - 文件流下載


//文件流下載
import axios from 'axios';
// 導出全部
        download() {
            this.btnloading = true;
            axios.get('/admin/annex/guwencard/downloadxcx', { params: { lpid: this.lpid } }).then((res) => {
                if (res.status == 200) {
                    // 利用a標簽自定義下載文件名
                    const link = document.createElement('a');
                    // 創建Blob對象,設置文件類型
                    let blob = new Blob([res.data.data.url], {
                        type: 'application/zip',//MIME類型
                    });
                    link.href = URL.createObjectURL(blob); // 創建URL
                    link.setAttribute('download', this.lpname + '.zip'); // 設置下載文件名稱
                    link.click(); // 下載文件
                    document.body.appendChild(link);
                    URL.revokeObjectURL(link.href); // 釋放內存
                    this.btnloading = false;
                } else {
                    this.$message.error(res.statusText);
                    this.btnloading = false;
                }
            });
        },

//普通下載
                   const link = document.createElement('a');
                    link.href = downpath;
                    link.setAttribute('download', this.lpname + '.zip'); // 設置下載文件名稱
                    link.click(); // 下載文件


免責聲明!

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



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