参考:https://www.cnblogs.com/libinfs/p/8080985.html

  let data = res.data;  //csv数据
  let filename = main.label + ".csv";   //导出的文件名
  let type = "";                      //头部数据类型
  let file = new Blob(["\ufeff" + data], { type: type });
  if (window.navigator.msSaveOrOpenBlob)
      // IE10+
      window.navigator.msSaveOrOpenBlob(file, filename);
    else {
      // Others
      let a = document.createElement("a"),
          url = URL.createObjectURL(file);
      a.href = url;
      a.download = filename;
      document.body.appendChild(a);
      a.click();
      setTimeout(function() {
        document.body.removeChild(a);
        window.URL.revokeObjectURL(url);
      }, 0);
    }
}

调用或封装成函数可下载csv文件

Logo

前往低代码交流专区

更多推荐