更换下载方式

This commit is contained in:
faiz 2024-12-20 10:12:47 +08:00
parent a75b47c218
commit 0bcc07119e
1 changed files with 28 additions and 8 deletions

View File

@ -74,6 +74,7 @@
<script>
import { exportFileLstApi, excelFileType } from "@/api/order";
import axios from 'axios';
export default {
name: "FileList",
data() {
@ -126,14 +127,33 @@ export default {
},
//
downLoad(path) {
// window.open(path)
const fileUrl = path; // URL
const link = document.createElement('a');
link.href = fileUrl;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// downLoad(path) {
// // window.open(path)
// const fileUrl = path; // URL
// const link = document.createElement('a');
// link.href = fileUrl;
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
// },
//
async downLoad(path) {
try {
const response = await axios.get(path, {
responseType: 'blob'
});
const url = window.URL.createObjectURL(new Blob([response.data]));
const a = document.createElement('a');
a.href = url;
a.download = path.split('/').pop(); // 使
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
} catch (error) {
console.error('下载错误:', error);
this.$message.error('文件下载失败');
}
},
pageChange(page) {
this.tableFrom.page = page;