element-ui table表格表头项动态渲染

根据后端返回数据,动态渲染table

 

<el-table 
          :data="dataList"
          show-summary
          :summary-method="getSummaries"
          class="myTable"
      >
          <template slot="empty">
            <empty-in-table></empty-in-table>
          </template>
          <!-- 合计字段可以排序 -->
          <el-table-column v-for="(head,index) in tableHeader" 
              :key="index" 
              :label="head.label" 
              :prop="head.key"
              :sortable="head.key == 'total_cost'"
            >
            <template slot-scope="scope">
                <span v-if="head.key.includes('cost')">{{'¥'+scope.row[head.key]}}</span>
                <span v-else>{{scope.row[head.key]}}</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="ts-page-block">
             <pagination
                :paginationData="pagination"
                @handleCurrentChange="handleCurrentChange"
                @handleSizeChange="handleSizeChange"
                >
             </pagination>
        </div>

请求接口数据:

getListData(obj){
            let { selectVal, dateVal, dep_name } = obj || this;
            console.log(dateVal);
            let { current_page,  per_page } = obj || this.pagination;
            let parm = {
                statistical_type: selectVal,
                statistical_period: moment(dateVal).format("YYYY-MM-DD"),
                current_page,
                per_page,
                pay_type: 1, // 付费方式:转售付费1;包年包月2;按需付费3;包年包月+按需付费4
                dep_name: selectVal == 'app' ? dep_name : '', // 部门赛选,只有维度为应用系统时
            };
            requestMethod.getChargeList('get', parm).then(res => {
                if(res.code == 200){
                    this.tableHeader = res.data.item.table_name_head;
                    this.dataList = res.data.item.table_body;
                    this.tableTotal = res.data.item.sum_cha_list;
                    if(selectVal == 'app'){
                        this.depArr =  this.depArr.length > 0 ? this.depArr : res.data.item.table_body.map(item => item.dep_name);
                    } else {
                        this.depArr = [];
                    }
                }else{
                    this.$message.error(res.message);
                }
            })
        },

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值