合并
表头合并:el-table中加上这个方法
:header-cell-style="handerMethod"
方法:
// 合并表头这里合并的是2、3
handerMethod({ row, column, rowIndex, columnIndex }) {
console.log(row,'row');
if (row[1].level === 1) {
// 这里有个非常坑的bug 必须是row[0]=0 row[1]=2才会生效
row[1].colSpan = 0
row[2].colSpan = 2
if (columnIndex === 1) {
return { display: 'none' }
}
}
},
单元格合并:和表头合并在同个位置加上这个方法: :span-method="genderSpanCity"
方法:
genderSpanCity({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0 || columnIndex === 1 ) {//第一列和第二列有相同的就合并
const cacheKey = `${rowIndex}-${columnIndex}`
if (this.cache[cacheKey]) {
return this.cache[cacheKey]
}
const currentValue = row[column.property]
const preRow = this.tableData[rowIndex - 1]
const preValue = preRow ? preRow[column.property] : null
if (currentValue === preValue) {
this.cache[cacheKey] = { rowspan: 0, colspan: 0 }
} else {
let rowspan = 1
for (l