element table展开行只显示一行

首先关键事件和属性

@expand-change="expandChange" :expand-row-keys="expands" :row-key="getRowKeys"

 expand-change 展开行change事件

 这里也只用第一个参数,

 expand-row-keys 绑定展开行的key值数组,设置为当前选择的key值就行

 row-key 辅助expand-row-keys的使用

 最终代码,亲测有效

<template>
  <el-table ref="table" :data="tableData"  @expand-change="expandChange" :expand-row-keys="expands" :row-key="getRowKeys">
    <el-table-column type="expand">
      <template>
        <el-table class="table-expand" :data="childTableData" >
            <el-table-column prop="category" label="z"></el-table-column>
            <el-table-column prop="address" label="x"></el-table-column>
            <el-table-column prop="shop" label="c"></el-table-column>
            <el-table-column prop="shopId" label="任务状态"></el-table-column>
          </el-table>
      </template>
    </el-table-column>
    <el-table-column label="Date" prop="date" />
    <el-table-column label="Name" prop="name" />
  </el-table>
</template>

<script lang="ts">
export default {
  data() {
    return {
      tableData: [
        {
          id:1,
          date: '2016-05-03',
          name: 'Tom',
          state: 'California',
          city: 'Los Angeles',
          address: 'No. 189, Grove St, Los Angeles',
          zip: 'CA 90036',
        },
        {
          id:2,
          date: '2016-05-02',
          name: 'Tom',
          state: 'California',
          city: 'Los Angeles',
          address: 'No. 189, Grove St, Los Angeles',
          zip: 'CA 90036',
        },
        {
          id:3,
          date: '2016-05-04',
          name: 'Tom',
          state: 'California',
          city: 'Los Angeles',
          address: 'No. 189, Grove St, Los Angeles',
          zip: 'CA 90036',
        }
      ],
      expands:[2],
      getRowKeys(row) {
        return row.id
      },
      childTableData: [
        {
          category: "江浙小吃、小吃零食",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333"
        }
      ],
    }
  },
  methods:{
    expandChange(row){
      this.expands = [row.id]
    }
  }
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值