美文网首页
React Excel表格导出传参问题

React Excel表格导出传参问题

作者: coderhzc | 来源:发表于2021-10-11 17:08 被阅读0次

    第一种方法(不带文件名称的导出):

    今天遇到一个Excel 表格导出传参问题

    筛选之后得到的数据,这是就要传参数了

      exportPlanData() {
        const eventTypeData = this.state.incidentValue ? this.state.incidentValue : ""
        const nameData = this.state.shipNameValue ? this.state.shipNameValue : ""
        window.location.href = "http://10.100.0.123/api/data/emergencyPlan/export?eventType=" + eventTypeData + "&name=" + nameData
      }
    

    实际截图:

    image.png

    第二种方法(导出带文件名称的):

      exportPlanData() {
        axios({
          url: BaseURL + "/data/emergencyPlan/export",
          params: {
            eventType: this.state.incidentValue ? this.state.incidentValue : "",
            name: this.state.shipNameValue ? this.state.shipNameValue : ""
          },
          responseType: "blob"
        }).then(res => {
          let fileName = "应急资源.xlsx";
          let blob = new Blob([res.data]);
          const link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = fileName;
          link.click(); //点击下载
          window.URL.revokeObjectURL(link.href);
          link.remove();
        }).catch(error => {
          message.error("导出失败")
        })
      }
    

    实际截图:

    image.png

    相关文章

      网友评论

          本文标题:React Excel表格导出传参问题

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