vue-element table 合并单元格


  export default { 

    data() { 

      return { 

        tableData6: [ 

          { 

            id: '12987122', 

            name: '王小虎', 

            amount1: '234', 

            amount2: '3.2', 

            amount3: 10 

          }, 

          { 

            id: '12987122', 

            name: '王小虎', 

            amount1: '165', 

            amount2: '4.43', 

            amount3: 12 

          }, 

          { 

            id: '12987122', 

            name: '王小虎', 

            amount1: '324', 

            amount2: '1.9', 

            amount3: 9 

          }, 

          { 

            id: '12987125', 

            name: '王小虎', 

            amount1: '621', 

            amount2: '2.2', 

            amount3: 17 

          }, 

          { 

            id: '12987126', 

            name: '王小虎', 

            amount1: '539', 

            amount2: '4.1', 

            amount3: 15 

          } 

        ], 

        column_row_offset: { 

          id: [3, 1, 1], 

          name: [2, 1, 1, 1], 

          amount1: [1, 1, 1, 1, 1], 

          amount2: [1, 1, 1, 1, 1], 

          amount3: [1, 1, 1, 1, 1] 

        }, 

        now_col_row_num: {}, 

        now_col_offset: {}, 


      }; 

    }, 

    methods: { 

      objectSpanMethod({ row, column, rowIndex, columnIndex }) { 

        if (!this.now_col_row_num[column.property]) { 

            if (!this.column_row_offset[column.property]) {// 假如column_row_offset中没有某一列合并规则,就不合并,根据实际情况而加by ly

                  return {

                    rowspan:1,

                    colspan:1

                  }

               }

          this.now_col_row_num[column.property] = Object.assign([], this.column_row_offset[column.property]); 

          let a = this.now_col_row_num[column.property].shift(); 

          this.now_col_offset[column.property] = a; 

          return { 

            rowspan: a, 

            colspan: 1 

          }; 

        } else if (rowIndex >= this.now_col_offset[column.property]) { 

          let a = this.now_col_row_num[column.property].shift(); 

          this.now_col_offset[column.property] += a; 

          return { 

            rowspan: a, 

            colspan: 1 

          }; 

        } else { 

          return { 

            rowspan: 0, 

            colspan: 0 

          }; 

        } 

      } 

    } 

  }; 



1.中必须有prop属性

2.不能使用show-overflow-tooltip(当内容过长被隐藏时显示 tooltip)

你可能感兴趣的:(vue-element table 合并单元格)