VUE el-table合并单元格,相同数据列合并


mergeColumn(){
  const spanOneArr = []
  let concatOne = 0
  this.repeatList.forEach(( item, index ) => {
    if (index === 0){
      spanOneArr.push(1)
    } else {
      //name 修改
      if (item.num === this.repeatList[index - 1].num){ //第一列需合并相同内容的字段
        spanOneArr[concatOne] += 1
        spanOneArr.push(0)
      } else {
        spanOneArr.push(1)
        concatOne = index
      }
    }
  })
  return {
    one: spanOneArr
  }
},
toMergeColumn({row, column, rowIndex, columnIndex}){
  if (columnIndex === 0 ) {
    const _row = (this.mergeColumn(this.repeatList).one)[rowIndex]
    const _col = _row > 0 ? 1 : 0
    return {
      rowspan: _row,
      colspan: _col
    }
  }
}

你可能感兴趣的:(VUE,vue.js,elementui,前端)