elementui的table根据是否符合需求合并列

javascript 复制代码
 <el-table :data="tableData" border style="width: 100%;" :span-method="objectSpanMethodAuto">
          <!-- 空状态 -->
          <template slot="empty">
            <div><img src="@/assets/images/noData.png" /></div>
            <span>暂无数据</span>
          </template>
          <el-table-column type="index" label="序号" width="80" align="center">
          </el-table-column>
          <el-table-column label="年度" align="center" prop="year">
          </el-table-column>
          <el-table-column prop="regionName" label="行政区划" align="center">
          </el-table-column>
          <el-table-column align="center">
            <template slot="header">
              <div class="header-con">(万人)</div>
              <div class="header-name">农业人口数量</div>
            </template>
            <template slot-scope="scope">
              <div>{{ scope.row.ruralPopNum }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header">
              <div class="header-con">(万人)</div>
              <div class="header-name">城镇人口数量</div>
            </template>
            <template slot-scope="scope">
              <div>{{ scope.row.urbanPopNum }}</div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="{ row }">
              <el-button type="text" size="small" class="operation" style="color: #2372ed;" @click="handleEditTable(row)">编辑</el-button>
              <el-button type="text" size="small" class="operation" style="color: #2372ed;" @click="handleDelete(row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
javascript 复制代码
data: function () {
      return {
       spanArr:[],
       tableData:[]
	}
}
javascript 复制代码
getList() {
      getPopList(this.query).then((res) => {
        this.totalCount = res.total;
        this.tableData = res.rows;
        let contactDot = 0;
        let spanArr = [];
        this.tableData.forEach((item, index) => {
          if (index === 0) {
            console.log(spanArr);
            spanArr.push(1);
          } else {
            if (item.year === this.tableData[index - 1].year) {
              spanArr[contactDot] += 1;
              spanArr.push(0);
            } else {
              contactDot = index;
              spanArr.push(1);
            }
          }
        });
        this.spanArr = spanArr;
      });
    },
javascript 复制代码
  // 合并行
    objectSpanMethodAuto({ row, column, rowIndex, columnIndex }) {
      console.log("点击:", row, column, rowIndex, columnIndex);
      if (columnIndex == 1 || columnIndex == 5) {
        if (this.spanArr[rowIndex]) {
          return {
            rowspan: this.spanArr[rowIndex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
相关推荐
VT.馒头7 分钟前
【力扣】2625. 扁平化嵌套数组
前端·javascript·算法·leetcode·职场和发展·typescript
数研小生36 分钟前
Full Analysis of Taobao Item Detail API taobao.item.get
java·服务器·前端
Shirley~~1 小时前
Vue-skills的中文文档
前端·人工智能
毎天要喝八杯水1 小时前
搭建vue前端后端环境
前端·javascript·vue.js
计算机程序设计小李同学1 小时前
幼儿园信息管理系统的设计与实现
前端·bootstrap·html·毕业设计
雨季6661 小时前
Flutter 三端应用实战:OpenHarmony “极简手势轨迹球”——指尖与屏幕的诗意对话
开发语言·javascript·flutter
雨季6662 小时前
Flutter 三端应用实战:OpenHarmony “专注时光盒”——在碎片洪流中守护心流的数字容器
开发语言·前端·安全·flutter·交互
tao3556672 小时前
【用AI学前端】HTML-02-HTML 常用标签(基础)
前端·html
2601_949532842 小时前
Psello HTML Template: A Developer‘s Deep-Dive Review and Guide - Download Free
前端·windows·html·seo·wordpress·gpl
CappuccinoRose2 小时前
CSS前端布局总指南
前端·css·学习·布局·flex布局·grid布局·float布局