vue +elementUI实现动态表格(表头也是动态)

本文介绍了如何在前端使用Element UI的el-table组件动态显示数据,通过V-for遍历后端返回的GZTitleModel表头和tableData。后端定义了包含label和property属性的表头实体,并通过Java映射到前端。
摘要由CSDN通过智能技术生成

废话不多说直接上代码

前端页面调用

<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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值