<el-table :data="listItem.data" :border="true" :span-method="objectSpanMethod">
   <el-table-column type="index" cell-style="40" width="100" align="center">
   </el-table-column>
</e-table>

  

data() {
  return {
  listItem: {
    data: [],
    loading: false
  },
  tempMergeIndex: [],
  }  
}

  

watch: {
        "listItem.data": {
            handler(arr) {
                var tempMergeIndex = [];
                var pos = null;
                for (let i = 0; i < arr.length; i++) {
                    if (i === 0) {
                        tempMergeIndex.push(1);
                        pos = 0;
                    } else {
                        if (arr[i].classType === arr[i - 1].classType) {
                            tempMergeIndex[pos] += 1;
                            tempMergeIndex.push(0);
                        } else {
                            tempMergeIndex.push(1);
                            pos = i;
                        }
                    }
                }
                this.tempMergeIndex = tempMergeIndex;
            },
            deep: true
        }
    },

  

method: {
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
            if (columnIndex === 0) {
                return {
                    rowspan: this.tempMergeIndex[rowIndex],
                    colspan: 1
                };
            }
        },
}

  

  

posted on 2021-12-07 16:57  我爱张苗苗  阅读(418)  评论(1编辑  收藏  举报