element 中的table表头动态渲染

自作多情 提交于 2020-03-07 02:38:47

element 中的table表头动态渲染

实际开发过程中遇到需求,表格中表头不一定是固定的,表头需要动态渲染。

<el-table :data="this.tableData"
              height="525">
      <el-table-column v-for="(item, index) in tableLabel"
                       :key="index"
                       :prop="item.prop"
                       :width="item.width"
                       :label="item.label">
      </el-table-column>
    </el-table>

这里的height="525"是为了固定头部

tableData: [// 表数据
        { id: 1, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 2, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 3, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 4, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 5, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 6, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 7, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 8, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 9, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 10, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 11, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 12, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 13, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 14, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
        { id: 15, date: '2018-07-24', sales: 23.34, sale: 137597.76, const: 102203.71, profit: 35394.05 },
      ],
      tableLabel: [ // 表头数据
        { label: 'id', width: '60', prop: 'id' },
        { label: '日期', width: '', prop: 'date' },
        { label: '销售量', width: '', prop: 'sales' },
        { label: '销售额', width: '', prop: 'sale' },
        { label: '成本', width: '', prop: 'const' },
        { label: '利润', width: '', prop: 'profit' }
      ]

感谢这篇文章vue element 中的table动态渲染(动态表头)超棒的~

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!