vue 项目中excel文件导出:

exportData() {//点击方法名称

            jjrExport(this.years).then(res => {//this.years为请求参数

                console.log(res);

                const type = "application/vnd.ms-excel;charset=utf-8";//excel文件

                const blob = new Blob([res], { type: type });

                const createA = document.createElement("a");

                const href = window.URL.createObjectURL(blob);

                createA.href = href;

                createA.download = `${new Date().Format("yyyy")}节假日数据统计.xls`;

                document.body.appendChild(createA);

                createA.click();

                document.body.removeChild(createA);//下载完成后移除标签

                window.URL.revokeObjectURL(href);//释放url

            })

        }

 

接口返回数据示例:

  1. Blob {size: 5120, type: "application/vnd.ms-excel"}
    1. size: 5120
    2. type: "application/vnd.ms-excel"
    3. __proto__: Blob
      1. size: (...)
      2. type: (...)
      3. slice: ƒ slice()
      4. stream: ƒ stream()
      5. text: ƒ text()
      6. arrayBuffer: ƒ arrayBuffer()
      7. constructor: ƒ Blob()
      8. Symbol(Symbol.toStringTag): "Blob"
      9. get size: ƒ size()
      10. get type: ƒ type()
      11. __proto__: Object
Logo

前往低代码交流专区

更多推荐