lilei 3 năm trước cách đây
mục cha
commit
fe50813f65
2 tập tin đã thay đổi với 13 bổ sung1 xóa
  1. 12 0
      src/api/dowloadFile.js
  2. 1 1
      src/views/dowloadFile/list.vue

+ 12 - 0
src/api/dowloadFile.js

@@ -11,3 +11,15 @@ export const taskList = (params) => {
     method: 'post'
   })
 }
+
+// 下载文件
+export const dowloadFile = (url, label) => {
+  axios.get(url, { responseType: "blob" }).then(response => {
+     const blob = new Blob([response.data]);
+     const link = document.createElement("a");
+     link.href = URL.createObjectURL(blob);
+     link.download = label;
+     link.click();
+     URL.revokeObjectURL(link.href);
+   }).catch(console.error);
+}

+ 1 - 1
src/views/dowloadFile/list.vue

@@ -45,7 +45,7 @@
         bordered>
         <!-- 操作 -->
         <template slot="action" slot-scope="text, record">
-          <a :href="record.fileUrl" :download="record.fileUrl" target="_blank" style="padding: 5px 0 0 23px;display: block;" v-if="record.taskState=='SUCCESS'">下载文件</a>
+          <a :href="record.fileUrl" download target="_blank" style="padding: 5px 0 0 23px;display: block;" v-if="record.taskState=='SUCCESS'">下载文件</a>
           <span v-else>--</span>
         </template>
       </s-table>