我想使用vue调用axios,通知后台查询数据,然后填入本地的excel文件中。然后再用vue通过axios,实现下载excel的效果。
我的excel模板test.xlsx放在public/file文件夹中,代码如下,但运行时系统报警:Not Found: /vue/file/test.xlsx
请帮看一下代码该怎么修改,谢谢!
<el-button icon="el-icon-download" size="small" @click="download_analy">下载分析表</el-button>
download_analy(){
this.axios({
method: 'get',
url: 'http://127.0.0.1:8000/app1/show_data/',
params: {
brand: this.brand, // 品牌
startdate: this.startdate, // 开始日期
}
}).then((response) => {
if (true) {
this.axios.get('file/test.xlsx', { //静态资源文件夹public
responseType: 'blob',
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
let fname = '分析表.xlsx';
link.href = url;
link.setAttribute('download', fname);
document.body.appendChild(link);
link.click();
})
}
});
},