js关于Blob对象的使用

Bolb可以用来改变一个文件的类型

 

 

 

// 下载导出内容
export function downloadFile(data, config = {}) {
  const aLink = document.createElement("a");
  let blob = new Blob([data], {
    type: (config as any).type || "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  })
  aLink.href = URL.createObjectURL(blob);
  aLink.download = (config as any).name;
  document.body.appendChild(aLink);
  aLink.click();
  document.body.removeChild(aLink);
}

 

posted @ 2020-10-23 11:21  遇你温柔如初  阅读(654)  评论(0编辑  收藏  举报