1、先安装依赖 自行百度搜索或csdn
2.引入:import table2excel from 'js-table2excel'
3、按钮点击事件(我是直接写在button按钮里面的 你们也可以写一个店家事件写进去)
onClick={() => { console.log(list); const column = [ //数据表单 { title: 'ID', //表头名称title key: 'id', //数据 }, { title: '姓名', key: 'name', }, { title: '性别', key: 'sex', }, { title: '年龄', key: 'age', }, { title: '学历', key: 'education', }, { title: '用工形式', key: 'title', }, { title: '档级', key: 'grade', }, { title: '所在项目', key: 'pname', }, { title: '在职状态', key: 'status', }, ]; let tableDatas = JSON.parse(JSON.stringify(list)); //将数据转化为字符串(list_data数据是接口数据,把名称换成自己的数据即可) let datas = tableDatas; table2excel(column, datas, '数据'); //表单数据名称 }}