后台返回的数组包对象格式的数据转换成表格数据格式的方法
transformDate(res) {const mapInfo = {id: '编号',password: '密码',mobile: '手机号',username: '姓名',timeOfEntry: '入职日期',formOfEmployment: '聘用形式',correctionTime: '转正日期',workNumber: '工号',departmentName: '部门',staffPhoto: '头像地址'}// // 取出所有的属性名字const pros=Object.keys(res[0])// 将属性名字转换成中文const header=props.map(zhwen=>mapInfo[zhKey])//取出所有数据const data = res.map(obj => Object.values(obj))return {header, data }}async hExportExcel() {// 1. ajax获取数据await this.loadEmployees()// console.log(this.list)// 2. 数据格式转换 ---> header, dataconst {header, data } = this.transformDate(this.list)console.log(header, data)// 3. 导出成excel文件// import('@/xxxx/Export2Excel').then(excel => {// excel.export_json_to_excel({// header,// data,// filename: '员工数据'//})//})},
在这里插入
描述