<table ref="myTable" cellpadding="0" cellspacing="0" class="my-table">
<thead>
<tr>
<th>考核维度</th>
<th>考核指标</th>
<th>考核标准</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center">
内容1
</td>
<td class="text-center">
内容1
</td>
<td class="text-center">
内容1
</td>
</tr>
</tbody>
</table>
mounted() {
this.$nextTick(() => {
this.mergeCells();
});
},
mergeCells() {
const table = this.$refs.myTable;
const rows = Array.from(table.tBodies[0].rows);
let lastRow = null;
let lastValue = null;
let rowspan = 1;
rows.forEach(function(row) {
const cell = row.cells[0];
const value = cell.textContent.trim();
if (lastRow) {
if (value === lastValue) {
lastRow.cells[0].rowSpan = ++rowspan;
cell.style.display = 'none';
} else {
lastRow = row;
lastValue = value;
rowspan = 1;
}
} else {
lastRow = row;
lastValue = value;
}
});
},