• 关于后台返回的文件流下载方法


    1.开发中一直使用的插件来做的var fileDownload = require('js-file-download'),但是发现safari下载不了 于是更改方法

    2.

    this.$axios({
                        method: 'post',
                        url: '/api/market/exportEmployee.do',
                        // headers里面设置token
                        headers: {
                          'Content-Type': 'application/json',
                          // "token":window.sessionStorage.getItem('token')
                        },
                        data: {
                            'department_id': parseInt(window.sessionStorage.getItem("departmentId")),
                              'startTime': this.date +'-1',
                              'endTime': this.date +'-31'
                        },
                        // 二进制流文件,一定要设置成blob,默认是json
                        responseType: 'blob'
    
                    }).then(res => {
                        console.log(res)
                        if(!res.data){
                                   return
                               }
                               var name = this.date + "月" + this.departmentName +"销售分析统计.xls";
                               var blob = new Blob([res.data]);
                               var url = window.URL.createObjectURL(blob);
                               var aLink = document.createElement("a");
                               aLink.style.display = "none";
                               aLink.href = url;
                               aLink.setAttribute("download", name);
                               document.body.appendChild(aLink);
                               aLink.click();
                               document.body.removeChild(aLink); //下载完成移除元素
                               window.URL.revokeObjectURL(url); //释放掉blob对象
                      })
    

      

  • 相关阅读:
    树的前序 中序 后序遍历
    算法入门经典-第四章 例题4-3 救济金发放
    算法入门经典-第五章 例题6-10 下落的树叶
    排序(三) 选择排序

    printf格式输出总结
    并查集
    异或的应用
    ActionContext详解
    ActionContext表格总结
  • 原文地址:https://www.cnblogs.com/yn-cn/p/14822566.html
Copyright © 2020-2023  润新知