vue中表格行展开

1、给表格加上方法 @expand-change="onExpandsRow"

<el-table
        :data="tableData"
        stripe
        border
        highlight-current-row
        v-loading="listLoading"
        ref="table"
        @expand-change="onExpandsRow"
      >
        <el-table-column type="expand">
          <template slot-scope="{ row }">
            <div class="expand-table" v-if="row.dtl">
              <table width="100%" border="0" cellspacing="1" :data="row.dtl">
                <tr>
                  <th width="4%" align="center">序号</th>
                  <th width="14.5%" align="center">内容编码</th>
                  <th>内容</th>
                </tr>
                <tr v-for="(item, index) in row.dtl" :key="index">
                  <td align="center">{{ index + 1 }}</td>
                  <td align="center">{{ item.checklistId }}</td>
                  <td>{{ item.content }}</td>
                </tr>
              </table>
            </div>
            <div v-else style="text-align: center">
              暂无内容
            </div>
          </template>
        </el-table-column>
        <el-table-column
          type="index"
          label=""
          min-width="50"
          align="center"
        ></el-table-column>
       
      </el-table>

 2、从后台返回的表格数据结构里面含有dtl为null,所以是传入id请求数据

//展示行
    onExpandsRow(row, index, e) {
      if (row.dtl) {
        !index && this.$refs.table.toggleRowExpansion(row);
      } else {
        this.listLoading = true;
        let param = { id: row.siteClassId };
        this.$api.请求方法(param)
          .then(res => {
            this.listLoading = false;
            if (res.data.code == 0) {
              row.dtl = res.data.data;
            }
            !index && this.$refs.table.toggleRowExpansion(row);
          })
          .catch(error => {
            this.listLoading = false;
          });
      }
    }

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~犇犇~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值