根据文件流进行下载文件方法

41 阅读1分钟
export function downloadFile(file, name, type) {
  const link = document.createElement('a')
  link.href = window.URL.createObjectURL(new Blob([file], {
    type: type
  }))
  link.target = '_blank'
  link.download = name
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
}