1. table表格开展行
(1)性能需要:点击table某行任意地位,则开展该行二级表格,同时收起其余行开展。
(2)实现办法:
//template<el-table :data="tableData" @row-click="getRowClick" row-key="no" :expand-row-keys="expands"> <el-table-column prop="no" label="序号" width="65"></el-table-column> <el-table-column prop="recordId" label="入库编号"></el-table-column> <el-table-column type="expand"> //二级表格 <template slot-scope="scope"> <div class="childrenClass"> <el-table :data="scope.row.productDetails"> <el-table-column prop="name" label="产品名称"> </el-table-column> </el-table> </div> </template> </el-table-column></el-table>//scriptexpands: [];//获取须要开展行的no属性,并赋值给开展行办法的数组getRowClick(row: any) { if (this.expands.indexOf(row.no) < 0) { this.expands = []; this.expands.push(row.no); } else { this.expands = []; }}
(3)办法介绍:
@row-click:当某一行被点击时会触发该事件;
row-key:行数据的 Key,用来优化 Table 的渲染,此我的项目应用tableData中的no属性作为key;
expand-row-keys:能够通过该属性设置 Table 目前的开展行,须要设置 row-key 属性能力应用,该属性为开展行的 keys 数组。
粗体
(4)实现成果: