vue.js导出excel表格
vue页面
<el-button id=“button” size=“medium” type=“primary”
@click=“export2Excel”>导出明细
js
//导出excel表格
export2Excel() {
require.ensure([], () => {
const { export_json_to_excel } = require(’@/vendor/Export2Excel.js’);
const tHeader = [‘id’,‘名称’, ‘收入’]; //1
const filterVal = [‘id’, ‘bookName’, ‘total’]; //2
const list = this.list;
const data = this.formatJson(filterVal, list);
export_json_to_excel(tHeader, data, ‘图书收入排行excel’);
})
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]))
},