Ver Fonte

解决图片下载不了的问题

unknown há 1 semana atrás
pai
commit
5f61393fc1

+ 8 - 13
src/components/Table2/index.vue

@@ -567,19 +567,14 @@ const handleSelectable = (row) => {
 
 
 const handleDownload = (row: FileItem) => {
-  fetch(row.fileUrl)
-    .then((response) => response.blob())
-    .then((blob) => {
-      const url = URL.createObjectURL(blob)
-      const a = document.createElement('a')
-      a.href = url
-      a.download = row.fileName
-      document.body.appendChild(a)
-      a.click()
-      document.body.removeChild(a)
-      setTimeout(() => URL.revokeObjectURL(url), 100);
-    })
-    .catch((error) => console.error('下载失败:', error))
+  const a = document.createElement('a')
+  a.href = row.fileUrl
+  a.download = row.fileName
+  a.target = '_blank'
+  a.rel = 'noopener noreferrer'
+  document.body.appendChild(a)
+  a.click()
+  document.body.removeChild(a)
 }
 
 const getDictLabelArr = (dictArr, field) => {

+ 8 - 13
src/components/UploadFile/src/TableUpload.vue

@@ -158,19 +158,14 @@ const handleRemove = (index: number, row: FileItem) => {
 }
 
 const handleDownload = (row: FileItem) => {
-  fetch(row.fileUrl)
-    .then((response) => response.blob())
-    .then((blob) => {
-      const url = URL.createObjectURL(blob)
-      const a = document.createElement('a')
-      a.href = url
-      a.download = row.fileName
-      document.body.appendChild(a)
-      a.click()
-      document.body.removeChild(a)
-      URL.revokeObjectURL(url)
-    })
-    .catch((error) => console.error('下载失败:', error))
+  const a = document.createElement('a')
+  a.href = row.fileUrl
+  a.download = row.fileName
+  a.target = '_blank'
+  a.rel = 'noopener noreferrer'
+  document.body.appendChild(a)
+  a.click()
+  document.body.removeChild(a)
 }
 
 watch(