/**导出 */
    async toExcel() {
      // let result = await this.axios({
      //   method: 'get',
      //   url: `issdc-manage/gameController/export.do`,
      // });
      // window.open(`${this.serverUrl}/issdc-manage/gameController/export.do=${this.selectedRowKeys}`);
      await this.axios({
        method: 'get',
        url: `entryFormController/export.do`,
        data: data,
        params: data,
        responseType: 'blob', //返回是个文件
      }).then((response) => {
        download(response, data); //then直接下载,方法在下边
      });

      // 下载文件
      function download(res) {
        let blob = new Blob([res.data], { type: res.headers['content-type'] }); //type是文件类,详情可以参阅blob文件类型
        // 创建新的URL并指向File对象或者Blob对象的地址

        let dis = res.headers['content-disposition'];
        let fileName = decodeURIComponent(dis.split('attachment;filename=')[1]);
        const blobURL = window.URL.createObjectURL(blob);
        // window.open(blobURL);
        var downloadElement = document.createElement('a');

        downloadElement.href = blobURL;

        downloadElement.download = fileName;

        document.body.appendChild(downloadElement);

        downloadElement.click();

        document.body.removeChild(downloadElement);

        window.URL.revokeObjectURL(blobURL);
      }
    },

 

posted on 2022-09-21 10:00  前端学习/vue  阅读(111)  评论(0编辑  收藏  举报