vue 下载文件

需求: 一个可以下载的接口,前端做出导出功能     接口:  https://www.cnblogs.com/kaibindirver/p/15470706.html

 方法一:

axios请求参数要加上       参考: https://www.cnblogs.com/kaibindirver/p/15396789.html 

responseType: 'arraybuffer'
axios.post('/con/mindmap/download',param,{
               "Content-Type":"application/octet-stream",
               responseType: 'arraybuffer'
            }).then(resopnse=>{
    console.log(1111)
      }
    },
其他下载下来的文件格式对应不同的TYpe 见 https://blog.csdn.net/weixin_48474646/article/details/128914894
压缩包用responseType: 'blob'

 方法二:

调用时加上红色的代码
复制代码
async down2(){
        let { response } = await rzCheck02(`fortime=${this.time1}&query=${this.selctaction}&totime=${this.time2}&index=2`);
        const objectUrl = window.URL.createObjectURL(new Blob([response], {type: "application/vnd.ms-excel"}));
        const a = document.createElement('a');
        a.href = objectUrl;
        a.download = '2023.xls';
        a.click();
        a.remove();
},
复制代码

 

方法三:

用open可行,单交互是会再起一个标签页下载

async down(){
// window的方法可行
window.open(`/v2/tool/check?fortime={this.time1}&query={this.selctaction}&totime={this.time2}&index=2&type={this.type}&page=4000`)
},
 
 
后计:
2023-6-7
今日有个接口需要接收file xlsx的文件 
然后结合了 方法一 和 方法二 才完成
https://www.cnblogs.com/kaibindirver/p/17463066.html
posted @   凯宾斯基  阅读(332)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-01-13 性能命令
2021-01-13 mac下top
2021-01-13 vue简单的富文本实现(亲测可以)
2020-01-13 使用命令行执行需要传参的 py文件的方法
点击右上角即可分享
微信分享提示