Element UI Table合并行

data() {
      return {
        listLoading: false,
        tableData: [],
        columnArray: [],
        serviceDomainArray: [],
        spanArr: [],
        pos: 0
      }
    },


 methods: {
      objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 1) {
          const _row = this.spanArr[rowIndex]
          const _col = _row > 0 ? 1 : 0
          return {
            rowspan: _row,
            colspan: _col
          }
        }
      },
      getSpanArr(data) {
        this.spanArr = []
        for (var i = 0; i < data.length; i++) {
          if (i === 0) {
            this.spanArr.push(1)
            this.pos = 0
          } else {
            // 判断当前元素与上一个元素是否相同
            if (data[i].parentName === data[i - 1].parentName) {
              this.spanArr[this.pos] += 1
              this.spanArr.push(0)
            } else {
              this.spanArr.push(1)
              this.pos = i
            }
          }
        }
      }
},

mounted() {
this.getSpanArr(this.dataList)
}
 
原文地址:https://www.cnblogs.com/rain-in-summer/p/9395978.html