# table合并单元格

An image

//代码写在[表.js]文件中,与onInint同级别,或者放onInit方法后面

//2023.08.19增加行、列合并功能,el合并文档见
//https://element-plus.gitee.io/zh-CN/component/table.html#%E5%90%88%E5%B9%B6%E8%A1%8C%E6%88%96%E5%88%97

//rows为当前页面所有的行数据
spanMethod({ row, column, rowIndex, columnIndex },rows) { 
      //spanMethod放在[表.js]文件中,与onInit方法同级
      //根据rowIndex, columnIndex 值按需要合并
      if (rowIndex % 2 === 0) {
        if (columnIndex === 6) {
          return [1, 2]
        } 
        else if (columnIndex === 5) {
           return [0, 0]
        }
      }
      if (columnIndex === 1) {
        if (rowIndex % 2 === 0) {
          return {
            rowspan: 2,
            colspan: 1,
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          }
        }
      }
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31