vue+iview-table点击展开展示内容,表格嵌套
实现如下效果的表格嵌套:
点击展开,展示tabs。
table的columns里设置展示的属性,然后属性里设置返回一个组件,然后在组件里写嵌套的内容。
<Table :columns="tableColumns" :data="tableData" style="width:100%" @on-selection-change="handleSelection"> <template #result="{ row, index }"> <Button type="success" size="small" style="margin-right: 5px" v-if="row.result === '成功'">成功</Button> <Button type="error" size="small" style="margin-right: 5px" v-if="row.result === '失败'">失败</Button> </template> </Table>
主要是tableColumns的设置:
第一个对象是table的勾选按钮;
第二个对象是点击展开的嵌套按钮,里面的ReviewPlanCode是组件,然后嵌套的tabs的内容都写到组件里。
和table一个页面的vue里引用ReviewPlanCode组件;
import ReviewPlanCode from './ReviewPlanCode';
components: { ReviewPlanCode },
tableColumns: [ { type: 'selection', width: 60, align: 'center' }, { key: 'action', type: 'expand', width:'30px', render: (h, row) => { return h(ReviewPlanCode, { props: { caseData: row.row } }) } }, { title: '执行计划', key: 'fileName', }, { title: '创建时间', key: 'time' }, { title: '创建人', key: 'operator', width:'150px', }, { title: '执行结果', key: 'result', width:'150px', slot: 'result' } ],
ReviewPlanCode组件内容:
<template> <Card> <Tabs value="name1"> <TabPane label="执行结果" name="name1"> <Table :columns="tableColumns" :data="tableData" style="width:100%" @expand="handleTableExpand(row)" @on-selection-change="handleSelection"> <template #result="{ row, index }"> <Button type="success" size="small" style="margin-right: 5px" v-if="row.result === '成功'">成功</Button> <Button type="error" size="small" style="margin-right: 5px" v-if="row.result === '失败'">失败</Button> </template> </Table> </TabPane> <TabPane label="计划详情" name="name2" > <pre v-highlight> <code style="height:300px;overflow: auto;"> {{ code }}</code> </pre> </TabPane> </Tabs> </Card> </template> <script> import { reviewCase } from '../../../api/webUI'; export default { name: 'ReviewPlanCode', props: { caseData:{ type: Object, } },
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2022-08-09 vue学习——自定义指令