- el-table处设置,必须要设置row-key
:expand-row-keys="expandRows"
:row-key="(row) => row.id"
@expand-change="handleExpandChange"
- data里声明
// 展开行
expandRows: [],
- 方法里添加
//控制展开行
handleExpandChange(row, expandedRows) {
if (expandedRows.length > 0) {
this.expandRows = [];
}
expandedRows.forEach((item) => {
this.expandRows.push(item.id);
});
},