Lia*_*ren 7 javascript download vue.js axios vuejs2
提前谢谢大家。
所以,我试图找到一个解决方案(谷歌搜索,没有找到任何东西)来流下载。我的意思是,我正在将数据导出到 csv 文件,但有时数据可能大到 7MB,这对于我的后端和用户来说都很重。
我正在用 Vue 编写我们的后端是用 PHP 编写的(Yii 1.1)
这就是我目前下载文件的方式
exportCsv() {
this.loading = true;
let payload = this.csvPayload; /// computed property
this.$http
.post("/statistics/apiurl", payload)
.then(response => {
this.loading = false;
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'excelFile.csv'); //or any other extension
document.body.appendChild(link);
link.click();
})
.catch(error => {
this.loading = false;
this.campaignsLoading = false;
console.log("Problem fetching csv file: ", error.message);
});
},
Run Code Online (Sandbox Code Playgroud)
这很棒!但同样,如果文件真的很大,那么后端和用户的负担就会很重。
就像我说的,有没有办法流式下载文件?或者,我想我可以在不同的文件中创建一个可观察的对象来监听数据,一旦完成传输,就会向我的 vue 组件发送回回调......
归档时间: |
|
查看次数: |
2082 次 |
最近记录: |