Vue 前端导出后端返回的excel文件
生活随笔
收集整理的這篇文章主要介紹了
Vue 前端导出后端返回的excel文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<Card class="mt20" title="設備數據"><div slot="extra"><a class="ml10" href="#" @click.prevent="toExcel"><Icon type="md-download" />導出設備表</a></div></Card>
// 導出excel表toExcel () {const data = {leftTime: this.leftTime,pageIndex: 1,pageSize: 10,rightTime: this.rightTime,type: 2}toExcel(data).then(res => {if (!res.data) {return}const blob = new Blob([res.data])const url = window.URL.createObjectURL(blob)const aLink = document.createElement('a')aLink.style.display = 'none'aLink.href = url// let fileName = decodeURIComponent(res.headers['content-disposition'].split('filename=')[1])aLink.setAttribute('download', '用戶活躍記錄表.xlsx')document.body.appendChild(aLink)aLink.click()document.body.removeChild(aLink) // 下載完成移除元素window.URL.revokeObjectURL(url) // 釋放掉blob對象}, err => {// 接口錯誤console.log(err)}).catch((err) => {// 處理邏輯出錯console.log(err)})},
仔細看axios請求加了個responseType: ‘blob’ 配置
export const toExcel = data => {return axios.request({url: 'xxxxx',data,method: 'post',responseType: 'blob'}) }總結
以上是生活随笔為你收集整理的Vue 前端导出后端返回的excel文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《2023 年 1-6 月中国游戏产业报
- 下一篇: 同程旅行盲盒机票怎么购买