首页 > 技术文章 > 前端和后端联调 导出excel功能

yeanling 2020-05-25 14:58 原文

方法代码:
payExcelClick (params) {
if (!params) {
params = {
pageSize: this.pageSize,
queryForm: this.queryForm
}
} else {
params.pageSize = this.pageSize
params.queryForm = this.queryForm
}
payExcelClick(params).then(({status, data}) => {
if (status === 200) {
const blob = new Blob([data], { type: "application/x-xls" })
const fileName = `合同_${new Date().getTime()}.xlsx`
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href)
document.body.removeChild(elink)
} else {
notify('获取信息失败', data.msg, 'error')
}
})
},


api:
// 导出当前页的应收
export function payExcelClick (params) {
return request({
url: '/xxxx/xxxx/xx/xxxx',
method: 'post',
headers: {
"biz-source-param": "BLG"
},
responseType: "blob",
data: params
})
}

推荐阅读