elementUI表格数据动态生成(实用有效!!!)

直接上代码:

// 第一种
<el-table height="100%" :data="tableData">
  <template v-for="(item, index) in tableHead">
    <el-table-column align="center" :label="item.column_comment" :key="index">
      <template slot-scope="scope">
        {{ scope.row[item.column_name] }}
      </template>
    </el-table-column>
  </template>
</el-table>

// 第二种
<el-table height="100%" :data="tableData">
  <template v-for="(item,index) in tableHead">
    <el-table-column align="center" :prop="item.column_name" :label="item.column_comment" :key="index"></el-table-column>
  </template>
</el-table>

数据:

// 表头数据
tableHead:[
    {
      column_name: "column_name",column_comment:"姓名"
    },
    {
      column_name: "column_age",column_comment:"年龄"
    },
    {
      column_name: "column_sex",column_comment:"性别"
    }
],
// 表格数据
tableData: [{
    column_age: '23',
    column_name: '李白',
    column_sex: '男'
  },
  {
    column_age: '25',
    column_name: '杜甫',
    column_sex: '男'
  },
  {
    column_age: '18',
    column_name: '李清照',
    column_sex: '女'
}],
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值