新的需求,将数据导出成excel表:
- 接口:
// 数据导出 axiosGet是封装后的get请求
export(activityId, config) { //{} 是因为封装的时候这个位置是放参数的,这里需要占个位,后面才是放配置的: {responseType: 'blob'},一定要传,不然打开excel是空白,提示文件扩展名无效。。。
return axiosGet(BASE_T_API + `/root/r1/activity/${activityId}/applicants/record/output`, {},config)
}
- 调接口(点击事件触发)
export () {
export () { //这里传参和配置(配置一定要有!!)
export(this.activityId, {responseType: 'blob'}).then(res => {
const data = res //new blob()处理后端返回的二进制文件流
const blob = new Blob([data],{type: 'application/vnd.ms-excel'})
const elink = document.createElement('a') //创建一个a标签
elink.href = URL.createObjectURL(blob) //设置a标签的href
elink.download = '列表.xlsx' //设置下载后的文件名
elink.style.dis