//导出记录
let _this = this
const padata = {
pageNum: this.pageNum,
pageSize: this.pageSize,
startTime: this.startTime,
endTime: this.endTime,
keywords: this.nameOrPhoneNumber,
appId: localStorage.getItem('appId')
}
let token = localStorage.getItem('token')
axios
.post('/api/merchant/outputVisitorLog', qs.stringify(padata), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded', //请求的数据类型为form data格式
'X-Access-Token': token
},
responseType: 'blob' //设置响应的数据类型为一个包含二进制数据的 Blob 对象,必须设置!!!
})
.then(response => {
if (response.data.code) {
_this.$message.error(response.msg)
} else {
const blob = new Blob([response.data], { type: 'application/octet-stream;charset=utf-8' })
const fileName = '访客预约记录.xls'
const linkNode = document.createElement('a')
linkNode.download = fileName //a标签的download属性规定下载文件的名称
linkNode.style.display = 'none'
linkNode.href = URL.createObjectURL(blob) //生成一个Blob URL
document.body.appendChild(linkNode)
linkNode.click() //模拟在按钮上的一次鼠标单击
URL.revokeObjectURL(linkNode.href) // 释放URL 对象
document.body.removeChild(linkNode)
}
})
.catch(error => {
console.log(error)
})
vue 导出xls
最新推荐文章于 2024-04-29 13:19:48 发布