美文网首页
导出excel下载

导出excel下载

作者: jesse28 | 来源:发表于2023-06-29 09:46 被阅读0次
        onConfirm(formName) {
          let loading = this.$loading({
            lock: true,
            customClass: "loading-bc",
          });
          caseInfoListExpApi({
            typeEnumCode: this.typeEnumCode,
            startingTime: this.form.startingTime,
            endTime: this.form.endTime,
            ...this.param,
          })
            .then((res) => {
              loading.close();
              console.log("确认", res);
              utils.downloadFile({
                fileName: "简易程序.xls",
                blob: res.data,
              });
    
              this.$emit("onClose");
            })
            .catch((err) => {
              loading.close();
            });
        },
    
    image.png

    封装的请求接口

    export const caseInfoListExpApi = (data) => {
        return request({
            url: `http://172.18.1.91:8615/exp/exp/caseInfoList`,
            method: "post",
            data,
            responseType: 'blob',
        })
    }
    

    utils.js的封装

    //下载文件
    const downloadFile = (file) => {
        // let responseData = await downLoadFile({fileId: data.id, fileName: data.name, d: 0}, 'blob');
        // let blob = new Blob([file.blob])
        // console.log("blob => ", blob.text());
        let downloadElement = document.createElement('a')
        let href = window.URL.createObjectURL(file.blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download = file.fileName; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放blob对象
    };
    

    相关文章

      网友评论

          本文标题:导出excel下载

          本文链接:https://www.haomeiwen.com/subject/bqmaydtx.html