1.导出按钮

 <el-form-item>
       <el-button @click="downloadExcel()" type="primary">导出</el-button>
 </el-form-item>

2.调用接口

     // 导出
      downloadExcel() {
       this.exportBalanceOrder()
      },

      async exportBalanceOrder(){
        let queryParams = this.queryParams;
        //调用接口
        await this.$api.tradeMgmt.exportOrderForm(queryParams).then((res) => {
          this.downloadCallback(res, '藏品交易记录.xls');
        });
      },

      //生成下载文件
      downloadCallback(res, fileName){
        const content = res.data;
        const blob = new Blob([content]);
        if ("download" in document.createElement("a")) {
          // 非IE下载
          const elink = document.createElement("a");
          elink.download = fileName;
          elink.style.display = "none";
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        } else {
          // IE10+下载
          navigator.msSaveBlob(blob, fileName);
        }
      },

3.接口文档

 //藏品交易记录导出
  exportOrderForm(params) {
    return axios.post(`/backstageOrder/exportOrderForm`, qs.stringify(params),{ responseType: "blob" });
  },

重点:接口里面一定要写  responseType: "blob"

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐