element-ui 合并单元格

html:
 <el-table
      :data="dataList"
      style="width: 100%;"
      :span-method="spanMethod"
    >
    </el-table>
    
data:
spanArr:[]
    
methods:
    getSpanArr (data) {
      this.spanArr = []
      if (data == null) {
        return
      }
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1)
          this.pos = 0
        } else {
          // 判断当前元素与上一个元素是否相同 card:相同的字段
          if (data[i].card === data[i - 1].card) {
            this.spanArr[this.pos] += 1
            this.spanArr.push(0)
          } else {
            this.spanArr.push(1)
            this.pos = i
          }
        }
      }
    },
    spanMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex < 4) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },

上一篇:扑克牌模拟算法题


下一篇:python之名片管理系统