data():{
return{
}
}
methods:{
getData(){
this.rowspan(0,‘stat_date‘);
this.rowspan(1,‘request_uri‘);
this.rowspan(2,‘total‘);
}
rowspan(idx, prop) { this.spanArr[idx] = []; this.position = 0; this.tableDataArr.forEach((item,index) => { if( index === 0){ this.spanArr[idx].push(1); this.position = 0; }else{ if(this.tableDataArr[index][prop] === this.tableDataArr[index-1][prop] ){ this.spanArr[idx][this.position] += 1;//有相同项 this.spanArr[idx].push(0); // 名称相同后往数组里面加一项0 }else{ this.spanArr[idx].push(1);//同列的前后两行单元格不相同 this.position = index; } } }) }, //表格单元格合并 cellMerge({ row, column, rowIndex, columnIndex }) { for(let i = 0; i<this.spanArr.length; i++) { if(columnIndex === i){ const _row = this.spanArr[i][rowIndex]; const _col = _row>0 ? 1 : 0; // console.log(‘第‘+rowIndex+‘行‘,‘第‘+i+‘列‘,‘rowspan:‘+_row,‘colspan:‘+_col) return { rowspan: _row, colspan: _col } } } }
}
element-UI动态渲染表格时相同数据表格合并,比如日期等数据相同的地方合并单元格,具体看代码
原文:https://www.cnblogs.com/bigkuan/p/13900942.html