element-ui el-table表格展开行 并且默认展开一行

element-ui el-table表格展开行 并且默认展开一行

效果图:
在这里插入图片描述

<el-table
          ref="table"
          :data="tablesData"
          style="width: 100%"
          :header-cell-style="{
            background: '#FAFAFA',
            color: '#000000',
            borderRight: '1px solid #fff'
          }"
          :height="tableHeight"
          :row-key="getRowKeys"
          :expand-row-keys="expands"
        >
          <el-table-column type="expand">
            <template slot-scope="scope">
              <el-form label-position="left" class="demo-table-expand">
                <el-form-item
                  :label="'同住人' + (index + 1)"
                  v-for="(item, index) in scope.row.mate_list"
                  :key="index"
                >
                  <span class="expand-text">{{ item.name }}</span>
                  <span class="expand-text">{{ sexType[item.gender] }}</span>
                  <span class="expand-text">{{ item.id_no }}</span>
                  <span class="expand-text">{{ item.phone_number }}</span>
                  <span>{{ item.relationship }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="#" width="55" align="center">
            <template slot-scope="scope">
              <span v-text="getIndex(scope.$index)"></span>
            </template>
          </el-table-column>
          <el-table-column label="承租人">
            <template slot-scope="scope">
              <span
                v-html="showDate(scope.row.name)"
                v-if="scope.row.name"
              ></span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column label="身份证号码" min-width="110">
            <template slot-scope="scope">
              {{ scope.row.id_no }}
            </template>
          </el-table-column>
          <el-table-column label="电话号码">
            <template slot-scope="scope">
              <span>{{ scope.row.phone_number }}</span>
            </template>
          </el-table-column>
        </el-table>

		data() {
    return {
      dataList: [],
      
      getRowKeys(row) {
        return row.id
      },
      
      // 要展开的行,数值的元素是row的key值
      expands: []
    }
   },
    mounted() {
	    // 放入默认展开行
	    this.expands.push(this.dataList[0].id)
  },
  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值