文件下载方法

This commit is contained in:
chenjianxing 2020-05-22 16:31:55 +08:00
parent bdac9282fc
commit 1f3ca6f5f2
1 changed files with 8 additions and 12 deletions

View File

@ -109,17 +109,14 @@ export default {
};
Vue.prototype.$fileDownload = function(url) {
axios({
method: 'get',
url: url,
responseType: 'blob',
}).then(response => {
let fileName = window.decodeURI(response.headers['content-disposition'].split('=')[1]);
let link = document.createElement("a");
link.href = window.URL.createObjectURL(new Blob([response.data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"}));
link.download = fileName;
link.click();
})
axios.get(url, {responseType: 'blob'})
.then(response => {
let fileName = window.decodeURI(response.headers['content-disposition'].split('=')[1]);
let link = document.createElement("a");
link.href = window.URL.createObjectURL(new Blob([response.data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"}));
link.download = fileName;
link.click();
});
};
Vue.prototype.$fileUpload = function(url, fileList, success, failure) {
@ -141,6 +138,5 @@ export default {
});
return result;
}
}
}