赞
踩
首先关键事件和属性
@expand-change="expandChange" :expand-row-keys="expands" :row-key="getRowKeys"
expand-change 展开行change事件
这里也只用第一个参数,
expand-row-keys 绑定展开行的key值数组,设置为当前选择的key值就行
row-key 辅助expand-row-keys的使用
最终代码,亲测有效
- <template>
- <el-table ref="table" :data="tableData" @expand-change="expandChange" :expand-row-keys="expands" :row-key="getRowKeys">
- <el-table-column type="expand">
- <template>
- <el-table class="table-expand" :data="childTableData" >
- <el-table-column prop="category" label="z"></el-table-column>
- <el-table-column prop="address" label="x"></el-table-column>
- <el-table-column prop="shop" label="c"></el-table-column>
- <el-table-column prop="shopId" label="任务状态"></el-table-column>
- </el-table>
- </template>
- </el-table-column>
- <el-table-column label="Date" prop="date" />
- <el-table-column label="Name" prop="name" />
- </el-table>
- </template>
-
- <script lang="ts">
- export default {
- data() {
- return {
- tableData: [
- {
- id:1,
- date: '2016-05-03',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036',
- },
- {
- id:2,
- date: '2016-05-02',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036',
- },
- {
- id:3,
- date: '2016-05-04',
- name: 'Tom',
- state: 'California',
- city: 'Los Angeles',
- address: 'No. 189, Grove St, Los Angeles',
- zip: 'CA 90036',
- }
- ],
- expands:[2],
- getRowKeys(row) {
- return row.id
- },
- childTableData: [
- {
- category: "江浙小吃、小吃零食",
- address: "上海市普陀区真北路",
- shop: "王小虎夫妻店",
- shopId: "10333"
- }
- ],
- }
- },
- methods:{
- expandChange(row){
- this.expands = [row.id]
- }
- }
- }
- </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。