Javascript 是否可以使用Vue.js流式下载大型文件?
先谢谢你 所以,我试图找到一个解决方案(谷歌搜索,没有找到任何东西)流下载。 我的意思是,我正在将数据导出到csv文件,但有时数据可能会大到7MB,这对我的后端和用户来说都很重 我在用Vue写作 我们的后端是用PHP编写的(Yii 1.1) 这就是我目前下载文件的方式Javascript 是否可以使用Vue.js流式下载大型文件?,javascript,vue.js,vuejs2,download,axios,Javascript,Vue.js,Vuejs2,Download,Axios,先谢谢你 所以,我试图找到一个解决方案(谷歌搜索,没有找到任何东西)流下载。 我的意思是,我正在将数据导出到csv文件,但有时数据可能会大到7MB,这对我的后端和用户来说都很重 我在用Vue写作 我们的后端是用PHP编写的(Yii 1.1) 这就是我目前下载文件的方式 exportCsv() { this.loading = true; let payload = this.csvPayload; /// computed pro
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);
});
},
太棒了!但是,如果文件真的很大,那么后端和用户的负担就很重
就像我说的,有没有一种方法可以流式下载文件?或者,我想我可以在另一个文件中创建一个可观察对象,该文件将侦听数据,并在传输完成后将回调发送回我的vue组件