码迷,mamicode.com
首页 > 其他好文 > 详细

Vue == 导出excel

时间:2019-11-27 22:01:19      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:ensp   position   form   for   day   customer   data   head   url   

<el-form-item>
    <el-button @click="exportHandle()" type="success">导出</el-button>
</el-form-item>

<script>
import axios from ‘axios‘
export default { methods:{ exportHandle() { axios({ headers: { ‘Content-Type‘:‘application/json‘, token: Cookies.get(‘tokensp‘) }, responseType: ‘blob‘, // 一定要写 method: ‘get‘, url:`${window.SITE_CONFIG[‘forumURL‘]}/productequipment/pmequipment/exportBackgroundEquipments`, params: { "json": { token: Cookies.get("token"), customerName:this.dataForm.customerName, businessOfficeId:this.dataForm.officeId, createTimeStart:‘‘, createTimeEnd:‘‘ } } }) .then(res => { let blob = new Blob([res.data], {type: ‘application/vnd.ms-excel‘}) let date = new Date(); let month = date.getMonth() + 1; let day = date.getDate(); let fileName = ‘设备管理信息‘ + date.getFullYear() + (month >= 10 ? month : ‘0‘ + month) + (day >= 10 ? day : ‘0‘ + day) // 下载的文件名 if (‘msSaveOrOpenBlob‘ in navigator){ // ‘IE‘ window.navigator.msSaveOrOpenBlob(blob, fileName + ‘.xls‘) } else { const link = document.createElement(‘a‘) link.style.display = ‘none‘ link.href = URL.createObjectURL(blob) link.download = res.headers[‘content-disposition‘] // 下载后文件名 link.download = fileName document.body.appendChild(link) link.click() document.body.removeChild(link) } }) .catch(err => { // console.log(err) }) } } } </script>

 

Vue == 导出excel

标签:ensp   position   form   for   day   customer   data   head   url   

原文地址:https://www.cnblogs.com/rabbit-lin0903/p/11945721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!