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