Code Is Never Die !
代码行中已标注实现点击行展开,并且自动收起其他行的相关设置和代码。
el-table表格是绑定在vue实例上的,相关配置、绑定数据、事件 将这三部分可以直接Copy到自己的项目相关位置,无需修改可以直接使用 !
1. el-table 相关配置
:row-key="getRowKeys"
:expand-row-keys="expands"
@expand-change="expandSelect"
@row-click="clickTable"
|
2. 绑定数据
expands: [],
getRowKeys(row) { return row.id; },
|
3. 点击行与展开事件
clickTable(row, index, e) { this.$refs.refTable.toggleRowExpansion(row); }, expandSelect(row, expandedRows) { var that = this; if (expandedRows.length) { that.expands = []; if (row) { that.expands.push(row.id); } } else { that.expands = []; } },
|
完整代码提供参考
<el-table :row-key="getRowKeys" :expand-row-keys="expands" @expand-change="expandSelect" @row-click="clickTable" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" :data="typeList" ref="refTable" > <el-table-column type="expand" width="30"> <template slot-scope="outer"> <div> <template> <el-table :data="handleData(holeData,outer.row)" style=" width: 100%; margin: 0 auto; border: 1px solid; border-color: #00a1d6; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-color: transparent; " > <el-table-column label="IP"> <template slot-scope="props"> <span>{{props.row.ip}}</span> </template> </el-table-column> <el-table-column label="端口"> <template slot-scope="props"> <span>{{props.row.duankou}}</span> </template> </el-table-column> <el-table-column label="操作"> <template slot-scope="props"> <el-button v-on:click="selectconnect(props.row,outer.row)" size="small" icon="el-icon-s-data" >弱口令破解</el-button > </template> </el-table-column> </el-table> </template> </div> </template> </el-table-column> <el-table-column label="类型"> <template slot-scope="props"> <span>{{props.row.netType}}</span> </template> </el-table-column> </el-table>
|
var testarea = new Vue({ el: '#workspace', data: { expands: [], getRowKeys(row) { return row.id; }, ...... }, methods: { clickTable(row, index, e) { this.$refs.refTable.toggleRowExpansion(row); }, expandSelect(row, expandedRows) { var that = this; if (expandedRows.length) { that.expands = []; if (row) { that.expands.push(row.id); } } else { that.expands = []; } }, ...... } })
|
PS: 博主博客主页(Rainux),精彩继续,欢迎来访!