<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>