废话不多说直接上代码
前端页面调用
<el-table :data="tableData" highlight-current-row style="width: 100%;margin-top: 30px; ">
<el-table-column
v-for="(item,index) in cols"
:key="index"
:label="item.label"
:property="item.property"
align="center">
<template slot-scope="scope">{{ scope.row[scope.column.property] }}</template>
</el-table-column>
</el-table>
后端定义表头实体
public class GZTitleModel {
private String label;
private String property;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
}
后端返回数据
Map<String, List> returnMap = new HashMap<>();
List cols = new ArrayList();
List<Map<String, Object>> tableData = new ArrayList();
LGTitleModel lts = new LGTitleModel();
lts.setLabel("姓名");
lts.setProperty("xm");
cols.add(lts);
Map map = new HashMap();
map.put("xm", "张三");
tableData.add(map);
returnMap.put("cols", cols);
returnMap.put("tableData", tableData);
return returnMap;