场景
- 将统计数据下载到excel中
参考文档
- axios
- maatwebsite/excel
分析
- 服务端是使用 Excel::download实现
- 客户端
- 原理: 生成一个超链接,然后触发它
axios.post(this.backend_history_download, {bill_history : this.tableRange, key : this.product_key}, {responseType: 'blob'}).then(response=>{
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', this.fileName); //or any other extension
document.body.appendChild(link);
link.click();
});