vue excel导出功能

<el-button type="primary" size="small" @click="exportExcel" :disabled="tableData.length === 0 ? true : false">导出Excel</el-button>
// 导出的方法
async exportExcel () {
  await axios.get(`/api/shop/excel?shopId=${this.user.shopId}&time=${this.dateValue}`, {responseType: 'arraybuffer'}).then(res => {
    console.log(res)
    let url = window.URL.createObjectURL(new Blob([res.data]), {type: 'application/vnd.ms-excel;charset=utf-8'})
    let link = document.createElement('a')
    link.style.display = 'none'
    link.href = url
    link.download = this.dateValue + '月医保对账单.xlsx'
    document.body.appendChild(link)
    link.click()
  })
}
发布了12 篇原创文章 · 获赞 0 · 访问量 1101

猜你喜欢

转载自blog.csdn.net/lq099526/article/details/103399488