vue的element-ui 两种 el-table 实现数据展现:默认加载固定字段展示与动态匹配字段展示

6 篇文章 0 订阅

el-table 实现数据展现:默认加载固定字段展示与动态匹配字段展示

 

第一种:默认加载固定展示

常规绑定数据集array默认为(gridList),代表返回数据集

也可以自定义,在初始化页面,加载返回: return {data:{data : dataArr, total: total}},gridList改为dataArr即可,total为分页返回数据。

         <el-table
          class="mt-5"
          v-loading="isShowLoading"
          :data="gridList"
          stripe
          :height='tableHeight'
          style="width: 100%"
           >
          <el-table-column
            align="left"
            prop="resApplyName"
            label="记录名称"
            >
          </el-table-column>
          <el-table-column
            align="left"
            prop="entityName"
            label="实体名称"
            >
            </el-table-column>
             <el-table-column
            align="center"
            width="280"
            label="操作">
            <template slot-scope="scope">
              <CommonButton type="text" label="详情" icon="el-icon-view"                                      
                 @click="seeDetaily(scope.row)">
              </CommonButton>
            </template>
          </el-table-column>
        </el-table>

 

 

第二种:动态匹配字段展示

常规绑定数据集array为tableData同理代表返回数据集(有key和value)。

columns字段名数组,

columnNames显示label数组。columns和columnNames是对应数组

用v-for循环遍历,实现tableData的key与columns配对,

显示columns和columnNames对应label显示,tableData的value展示

 

                             <el-table
                                :data="tableData"
                                style="width: 100%"
                                height="320"
                                stripe
                                border
                                v-loading="isShowLoading">
                                <!-- 自定义列的遍历-->
                                <el-table-column v-for="(item, index) in columns"             
                               :key="index" :label="colunmNames[index]" align="center">
                                <!-- 数据的遍历  scope.row就代表数据的每一个对象-->
                                <template slot-scope="scope">
                                <span>{{scope.row[item]}}</span>
                                </template>
                                </el-table-column>
                            </el-table>

就是这么傻,还在天真的玩耍中......

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值