Browse Source

优化下载

caner 2 years ago
parent
commit
697ec269a8
1 changed files with 2 additions and 4 deletions
  1. 2 4
      src/services/downloadFile.ts

+ 2 - 4
src/services/downloadFile.ts

@@ -14,12 +14,10 @@ export const downloadFile = (url: string | Blob, fileName: string) => {
         window.URL.revokeObjectURL(url)
     }
     let newUrl: any = ''
-    if (typeof url === 'object' && url instanceof Blob) {
+    if (url instanceof Blob) {
         newUrl = URL.createObjectURL(newUrl) // 创建blob地址
         download(newUrl, fileName)
     } else {
-        fetch(newUrl).then((res) => res.blob()).then((blob) => {
-            download(blob, fileName)
-        })
+        fetch(newUrl).then((res) => res.blob()).then((blob) => download(blob, fileName))
     }
 }