zoukankan      html  css  js  c++  java
  • 后端创文件流前端浏览器进行下载Excel(springboot+Vue)

    转载 https://blog.csdn.net/qq_34940644/article/details/99638156

        // 导出
        exportFun() {
          if (this.planListData.length === 0) {
            this.$message({
              message: "列表为空,无法导出",
              type: "error"
            });
            return;
          }
          this.isExport = false;
          this.exportList(this.searchData).then(res => {
              let blob = new Blob([res], {
                type:
                  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
              });
              let objectUrl = URL.createObjectURL(blob);
              let a = document.createElement("a");
              a.href = objectUrl;
              a.download = "补货计划报表";
              // a.click();
              //下面这个写法兼容火狐
              a.dispatchEvent(
                new MouseEvent("click", {
                  bubbles: true,
                  cancelable: true,
                  view: window
                })
              );
              window.URL.revokeObjectURL(blob);
          });
        },
        /**
        * @description 补货计划--列表-导出
        */
        async exportList({ dispatch }, params) {
            const res = await Axios.post(API.REPLENISH_PLAN_EXPORT.URL, params, { responseType: "blob" }).then(response => response)
                .catch(error => Promise.reject(error))
            return res;
        },
    async exportReport() {
          Axios.get("/sqdb/gwlog/v1/export", {
            params: {},
            responseType: "blob"
          }).then(res => {
            let blob = new Blob([res], {
              type:
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            });
            // console.log(blob);
            let objectUrl = URL.createObjectURL(blob);
    
            let a = document.createElement("a");
            a.href = objectUrl;
            a.download = "报表";
            // a.click();
            //下面这个写法兼容火狐
            a.dispatchEvent(
              new MouseEvent("click", {
                bubbles: true,
                cancelable: true,
                view: window
              })
            );
            window.URL.revokeObjectURL(blob);
          });
        },
  • 相关阅读:
    centos5.8下用shell脚本监控服务器
    linux下IPTABLES配置详解
    centos设置计划任务(cron)
    32位CentOS系统安装kernel-PAE支持4g以上内存
    Excel同时打开多个独立的窗口
    yum安装LAMP
    多字段指定不同方向排序
    MySQL基础
    Python 网络编程
    Python 并发编程
  • 原文地址:https://www.cnblogs.com/MR-cui/p/12454913.html
Copyright © 2011-2022 走看看