download.ts 950 B

12345678910111213141516171819202122232425
  1. export const downloadSVGFile = (str: string, name: string) => {
  2. const blob = new Blob([str], { type: "image/svg+xml" })
  3. const href = URL.createObjectURL(blob)
  4. const alink = document.createElement("a")
  5. alink.style.display = "none"
  6. alink.download = name // 下载后文件名
  7. alink.href = href
  8. document.body.appendChild(alink)
  9. alink.click()
  10. document.body.removeChild(alink) // 下载完成移除元素
  11. URL.revokeObjectURL(href) // 释放掉blob对象
  12. }
  13. export const downloadLinkFile = (link: string, name: string) => {
  14. // const blob = new Blob([str], { type: "image/svg+xml" })
  15. // const href = URL.createObjectURL(blob)
  16. const alink = document.createElement("a")
  17. alink.style.display = "none"
  18. alink.download = name // 下载后文件名
  19. alink.href = link
  20. document.body.appendChild(alink)
  21. alink.click()
  22. document.body.removeChild(alink) // 下载完成移除元素
  23. URL.revokeObjectURL(link) // 释放掉blob对象
  24. }