Saber2pr's Blog

保存文件到本地

利用 a 标签

download 属性为保存文件名

export function download(url: string, name = new Date().toLocaleString()) {
  const anchor = document.createElement("a")
  anchor.download = name
  anchor.href = url
  anchor.click()
  anchor.remove()
}

download url

  1. Canvas.toDataURL()

  2. URL.createObjectURL(Blob|File)