HTML代码:
<el-table
:data="tableList"
row-key="docId"
border
ref="refTable"
default-expand-all
height="calc(100vh - 196px)"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
// 自定义index
<el-table-column type="index" label="序号" width="80">
<template slot-scope="scope">
<span>{{scope.row.index}}</span>
</template>
</el-table-column>
</el-table>
JS代码:
getFindeCatalogList(data) {
getCataLogList(data).then((res) => {
this.tableList = [res.data];
if (this.tableList.length > 0) this.setTableIndex(this.tableList);
});
},
setTableIndex(arr, index) {
arr.forEach((item, key) => {
item.index = key + 1;
if (index) {
item.index = index + "-" + (key + 1);
}
if (item.children) {
this.setTableIndex(item.children, item.index);
}
});
},