线上体验地址
<template>
<div class="app-container home">
<el-card class="box-card">
<el-table :data="tableData" :span-method="objectSpanMethod" border>
<el-table-column
prop="id"
label="ID"
width="180"
align="center"
></el-table-column>
<el-table-column
prop="name"
label="银行"
align="center"
></el-table-column>
<el-table-column
prop="amount"
label="数值"
align="center"
></el-table-column>
<el-table-column label="操作" fixed="right" width="180" align="center">
<template>
<el-button type="text" size="small">修改</el-button>
<el-button type="text" size="small">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
</div>
</template>
<script>
export default {
name: "tableRow",
data() {
return {
rowspan: [],
tableData: [
{
id: 1,
name: "建设银行",
data: [
{ amount: "6,802.47" },
{ amount: "307,943.03" },
{ amount: "116,245.19" },
],
},
{
id: 2,
name: "中信银行",
data: [{ amount: "45.68" }, { amount: "264,938.09" }],
},
{
id: 3,
name: "招商银行",
data: [
{ amount: "23,028.52" },
{ amount: "130,017.66" },
{ amount: "899.75" },
{ amount: "5,110.80" },
],
},
],
};
},
created() {
this.initData();
},
methods: {
initData() {
let data = this.tableData;
let arr = [];
let rowspan = [];
data.forEach((item) => {
let { data = [], ...others } = item;
data = data.map((item, index) => {
if (index === 0) {
rowspan.push(data.length);
} else {
rowspan.push(0);
}
return { ...others, ...item };
});
arr.push(...data);
});
this.tableData = arr;
this.rowspan = rowspan;
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if ([0, 1, 3].includes(columnIndex)) {
const _row = this.rowspan[rowIndex];
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col,
};
}
},
},
};
</script>
<style scoped lang="scss">
</style>