一、效果展示
功能1:添加主表格一行
功能2:添加某个子表格一行
功能3:子表格数据的异步加载
二、代码实现
<template>
<div>
<a-button @click="add" type="primary" size="small" style="margin:20px">添加主表格数据</a-button>
<a-table
:columns="columns"
:data-source="data"
class="components-table-demo-nested"
@expand="getInnerData"
@expandedRowsChange="expandedRowsChange"
style="margin:20px"
>
<a slot="operation" slot-scope="row" @click="addInnderData(row)">添加子表格数据</a>
<a-table
slot="expandedRowRender"
slot-scope="inner"
:columns="innerColumns"
:data-source="inner.innerData"
:pagination="false"
>
<span slot="operation" slot-scope="text" class="table-operation">
<a-dropdown>
<a-menu slot="overlay">
<a-menu-item>Action 1</a-menu-item>
<a-menu-item>Action 2</a-menu-item>
</a-menu>
<a>
More
<a-icon type="down" />
</a>
</a-dropdown>
</span>
</a-table>
</a-table>
</div>
</template>
<script>
const columns = [
{
title: 'Name', dataIndex: 'name', key: 'name' },
{
title: