【发布时间】:2020-08-27 16:26:53
【问题描述】:
最近我尝试使用 Axios 下载 CSV 文件时,vue 应用出现问题,我不知道如何解决它。
downloadFile: function(res = "") {
axios
.get('/api/file/' + res, 'blob')
.then(({ data }) => {
const blob = new Blob([data], {type: 'text/csv'});
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = res;
link.click();
}).catch(error => console.error(error))
}
每当点击<div v-on:click="downloadFile(filename)"> 时,控制台上都会打印以下内容:
vue.min.js:6 TypeError: Cannot use 'in' operator to search for 'validateStatus' in blob
at spread.js:25
at Object.b [as forEach] (spread.js:25)
at e.exports (spread.js:25)
at r.<computed> [as get] (spread.js:25)
at Function.get (spread.js:25)
at a.downloadFile (eval at compile (http-vue-loader:161), <anonymous>:73:22)
at click (eval at Ya (vue.min.js:6), <anonymous>:3:1183)
at He (vue.min.js:6)
at HTMLDivElement.n (vue.min.js:6)
at HTMLDivElement.Yr.o._wrapper (vue.min.js:6)
【问题讨论】:
标签: javascript vue.js axios blob