html:

    <el-table id="out-table" :data="tableData" border :span-method="objectSpanMethod">

 

js:

methods内代码:

 getListDataForRowAndColumn(data){
      let self = this;
      self.rowAndColumn = [];
      self.rowRoomColumn = [];
       for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          // 如果是第一条记录(即索引是0的时候),向数组中加入1
          self.rowAndColumn.push(1);
          self.pos = 0;
           self.rowRoomColumn.push(1);
          self.posT = 0;
        } else {
          if (data[i].storeName === data[i - 1].storeName) {
            // 如果storeName相等就累加,并且push 0
            self.rowAndColumn[self.pos] += 1
            self.rowAndColumn.push(0)
            if (data[i].roomName === data[i - 1].roomName) {
                // 如果roomName相等就累加,并且push 0
                self.rowRoomColumn[self.posT] += 1
                self.rowRoomColumn.push(0)
            }else{
                self.rowRoomColumn.push(1)
                self.posT = i
            }
          } else {
            // 不相等push 1
            self.rowAndColumn.push(1)
            self.pos = i;
            self.rowRoomColumn.push(1)
            self.posT = i
          }
        }
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
       let self = this
       if (columnIndex === 0) {
         if (self.rowAndColumn[rowIndex]) {
           let rowNum = self.rowAndColumn[rowIndex];
           return {
               rowspan: rowNum,
               colspan: rowNum > 0 ? 1 : 0
             }                                                   
         }
         return {
             rowspan: 0,
             colspan: 0
           }  
       }
       if (columnIndex === 1) {
         if (self.rowRoomColumn[rowIndex]) {
           let roomNum = self.rowRoomColumn[rowIndex];
           return {
               rowspan: roomNum,
               colspan: roomNum > 0 ? 1 : 0
             }                                                   
         }
         return {
             rowspan: 0,
             colspan: 0
           }  
       }
     },

 

 

GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45 7 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐