前言
使用el-table做跨行跨列表格渲染,接口数据格式为对象数组,即需从对象中提取columns,且需要设置对应的跨行跨列关系。为此要实现一种更优雅的构造方法,即配置化跨行跨列动态渲染。
基于element-ui v2.4.11版本,实现对于该版本表格组件,跨行跨列的构造方法可以通过arraySpanMethod构造,由于笔者使用的是vue2写法,vue3雷同使用。
传送门:https://element.eleme.cn/2.4/#/zh-CN/component/table
methods: {
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
if (rowIndex % 2 === 0) {
if (columnIndex === 0) {
return [1, 2];
} else if (columnIndex === 1) {
return [0, 0];
}
}
}
}
2024/12/11大约 4 分钟
