标题、页脚与摘要行
这组能力用于在表格上下补充结构化信息。它们的分工可以简单理解为:
title表格上方的信息区footer表格下方的补充说明summary和当前数据直接相关的汇总行
title 也可以放入 VTableToolbar,组合标题、刷新、密度、列设置和业务按钮。通过工具栏的 #actions 加入导出等操作,完整示例见 工具栏与业务扩展。外层 VTable #title 提供 { data },内层工具栏插槽提供工具状态与方法,两者作用域不同。
在线示例
<script setup lang="ts">
import { computed } from 'vue'
import { VTable, VTableSummary } from '@vtable-guild/vtable-guild'
import type { TableColumnsType } from '@vtable-guild/vtable-guild'
interface DeptRow {
key: string
dept: string
headcount: number
budget: number
used: number
}
const columns: TableColumnsType<DeptRow> = [
{ title: '部门', dataIndex: 'dept', key: 'dept' },
{ title: '人数', dataIndex: 'headcount', key: 'headcount', align: 'right' },
{
title: '预算',
dataIndex: 'budget',
key: 'budget',
align: 'right',
customRender: ({ text }) => `¥ ${Number(text).toLocaleString()}`,
},
{
title: '已支出',
dataIndex: 'used',
key: 'used',
align: 'right',
customRender: ({ text }) => `¥ ${Number(text).toLocaleString()}`,
},
]
const dataSource: DeptRow[] = [
{ key: '1', dept: '平台组', headcount: 24, budget: 1200000, used: 864000 },
{ key: '2', dept: '交易组', headcount: 41, budget: 2050000, used: 1710500 },
{ key: '3', dept: '设计系统', headcount: 6, budget: 300000, used: 182000 },
{ key: '4', dept: '质量保障', headcount: 21, budget: 940000, used: 733000 },
]
const total = computed(() =>
dataSource.reduce(
(acc, row) => ({
headcount: acc.headcount + row.headcount,
budget: acc.budget + row.budget,
used: acc.used + row.used,
}),
{ headcount: 0, budget: 0, used: 0 },
),
)
const money = (value: number) => `¥ ${value.toLocaleString()}`
</script>
<template>
<VTable
row-key="key"
bordered
:columns="columns"
:data-source="dataSource"
:title="() => '2026 财年部门预算执行'"
:footer="() => '口径:含外包成本,不含办公场地分摊'"
>
<!-- Summary 的 index 对应列下标,align 单独控制摘要单元格对齐 -->
<template #summary>
<VTableSummary>
<VTableSummary.Row>
<VTableSummary.Cell :index="0">合计</VTableSummary.Cell>
<VTableSummary.Cell :index="1" align="right">{{ total.headcount }}</VTableSummary.Cell>
<VTableSummary.Cell :index="2" align="right">{{
money(total.budget)
}}</VTableSummary.Cell>
<VTableSummary.Cell :index="3" align="right">{{ money(total.used) }}</VTableSummary.Cell>
</VTableSummary.Row>
</VTableSummary>
</template>
</VTable>
</template>基础示例
摘要行组件从 VTableSummary 导入,Row / Cell 挂在它上面。Cell 的 index 对应列下标。
<script setup lang="ts">
import {
VTable,
VTableSummary,
type TableColumnsType,
type TableProps,
} from '@vtable-guild/vtable-guild'
interface ScoreRow {
key: string
name: string
score: number
}
const columns: TableColumnsType<ScoreRow> = [
{ title: '姓名', key: 'name', dataIndex: 'name' },
{ title: '分数', key: 'score', dataIndex: 'score', align: 'right' },
]
const dataSource: ScoreRow[] = [
{ key: '1', name: 'Ada', score: 95 },
{ key: '2', name: 'Grace', score: 92 },
]
const totalScore = dataSource.reduce((sum, row) => sum + row.score, 0)
const title: NonNullable<TableProps<ScoreRow>['title']> = (data) =>
`部门绩效总览 · ${data.length} 人`
const footer: NonNullable<TableProps<ScoreRow>['footer']> = () => '数据更新时间:今天 09:30'
</script>
<template>
<VTable
row-key="key"
:columns="columns"
:data-source="dataSource"
:title="title"
:footer="footer"
>
<template #summary>
<VTableSummary>
<VTableSummary.Row>
<VTableSummary.Cell :index="0">合计</VTableSummary.Cell>
<VTableSummary.Cell :index="1" align="right">{{ totalScore }}</VTableSummary.Cell>
</VTableSummary.Row>
</VTableSummary>
</template>
</VTable>
</template>title / footer 的函数签名都是 (data: TRecord[]) => VNodeChild;分页开启时接收当前页展示数据。对应的 #title / #footer 插槽接收 { data: TRecord[] },而 #summary 不提供参数。VNodeChild 是 Vue 的可渲染内容类型。
什么时候用哪一个
title标题、统计摘要、筛选说明、批量操作提示footer说明文字、更新时间、口径备注summary金额合计、平均值、总数和选中项汇总
使用边界
- 只是放一段说明文字时,优先用
title或footer summary更适合表达和当前数据直接相关的结果,而不是通用描述- 如果页面外层已经有完整卡片头部,表格
title可以只承载局部状态信息
API
TRecord 表示业务行类型。表格的完整配置见 API Reference。
Props
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
title | (data: TRecord[]) => VNodeChild | - | 表格标题区域渲染函数。 |
footer | (data: TRecord[]) => VNodeChild | - | 表格页脚区域渲染函数。 |
sticky | boolean | TableSticky | false | 粘性表头与摘要行;对象形式见配置项。 |
Slots
| Slot | 参数类型 | 说明 |
|---|---|---|
title | TableDataSlotProps<TRecord> | 自定义标题区域。 |
footer | TableDataSlotProps<TRecord> | 自定义页脚区域。 |
summary | () | 自定义摘要区域。 |
VTableSummary
| 组件 | 说明 |
|---|---|
VTableSummary | 摘要容器,放在表格的 #summary 插槽内。 |
VTableSummary.Row | 摘要行,没有 props。 |
VTableSummary.Cell | 摘要单元格。 |
VTableSummary Props
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
fixed | boolean | 'top' | 'bottom' | false | 固定摘要行;true 等同 'bottom'。 |
VTableSummary.Cell Props
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
index | number | 必填 | 单元格所在的列索引,从 0 开始。 |
colSpan | number | - | 跨列数。 |
rowSpan | number | - | 跨行数。 |
align | AlignType | - | 内容对齐方式。 |
主题
标题、页脚和摘要区域的 class 可通过实例 ui 或全局 theme.table.slots 覆盖。调整颜色或尺寸时可使用下方 CSS 变量。覆盖顺序见三层主题覆盖。
ui slots
| Slot | 说明 |
|---|---|
title | 表格标题区域。 |
footer | 表格页脚区域。 |
summary | 摘要容器。 |
summaryRow | 摘要 <tr>。 |
summaryCell | 摘要 <td>。 |
预设默认值
两套预设的默认 class 可用下方标签切换。默认预编译模式下 utility 的覆盖方式见前缀与覆盖规则。
createVTableGuild({
theme: {
table: {
slots: {
title: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)]',
footer: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)]',
summary: '',
summaryRow: 'bg-[color:var(--vtg-table-header-bg)]',
summaryCell: 'font-semibold bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)] border-b border-[color:var(--vtg-table-border-color)]',
},
variants: {
bordered: {
true: {
title: 'border-b border-[color:var(--vtg-table-border-color)]',
footer: 'border-t border-[color:var(--vtg-table-border-color)]',
summaryCell: 'border-r border-[color:var(--vtg-table-border-color)] last:border-r-0',
},
},
},
compoundSlots: [
{
slots: ['title', 'footer', 'summaryCell'],
size: 'large',
class: 'px-[var(--vtg-table-cell-padding-inline-lg)] py-[var(--vtg-table-cell-padding-block-lg)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'middle',
class: 'px-[var(--vtg-table-cell-padding-inline-md)] py-[var(--vtg-table-cell-padding-block-md)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'small',
class: 'px-[var(--vtg-table-cell-padding-inline-sm)] py-[var(--vtg-table-cell-padding-block-sm)]',
},
],
defaultVariants: {
size: 'large',
bordered: false,
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
table: {
slots: {
title: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)] font-medium',
footer: 'bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)]',
summary: '',
summaryRow: 'bg-[color:var(--vtg-table-header-bg)]',
summaryCell: 'font-medium bg-[color:var(--vtg-table-header-bg)] text-[color:var(--vtg-table-text-color)] border-b border-[color:var(--vtg-table-border-color)]',
},
variants: {
bordered: {
true: {
title: 'border-b border-[color:var(--vtg-table-border-color)]',
footer: 'border-t border-[color:var(--vtg-table-border-color)]',
summaryCell: 'border-r border-[color:var(--vtg-table-border-color)] last:border-r-0',
},
},
},
compoundSlots: [
{
slots: ['title', 'footer', 'summaryCell'],
size: 'large',
class: 'px-[var(--vtg-table-cell-padding-inline-lg)] py-[var(--vtg-table-cell-padding-block-lg)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'middle',
class: 'px-[var(--vtg-table-cell-padding-inline-md)] py-[var(--vtg-table-cell-padding-block-md)]',
},
{
slots: ['title', 'footer', 'summaryCell'],
size: 'small',
class: 'px-[var(--vtg-table-cell-padding-inline-sm)] py-[var(--vtg-table-cell-padding-block-sm)]',
},
],
defaultVariants: {
size: 'middle',
bordered: false,
},
},
},
})CSS 变量
表中列出亮色模式的默认值。暗色模式可通过 .dark 单独覆盖。
| 变量 | 作用 | antdv | element-plus |
|---|---|---|---|
--vtg-table-header-bg | 表头、标题、页脚、摘要行背景 | var(--color-surface-hover) | var(--color-surface) |
--vtg-table-text-color | 正文文字颜色 | var(--color-on-surface) | var(--color-text-regular) |
--vtg-table-border-color | 表格边框和单元格分隔线 | var(--color-default) | var(--color-default) |
--vtg-table-cell-padding-inline-lg | large 尺寸的横向内边距 | 16px | 12px |
--vtg-table-cell-padding-block-lg | large 尺寸的纵向内边距 | 16px | 12px |
--vtg-table-cell-padding-inline-md | middle 尺寸的横向内边距 | 8px | 12px |
--vtg-table-cell-padding-block-md | middle 尺寸的纵向内边距 | 12px | 8px |
--vtg-table-cell-padding-inline-sm | small 尺寸的横向内边距 | 8px | 12px |
--vtg-table-cell-padding-block-sm | small 尺寸的纵向内边距 | 8px | 4px |
Type Declarations
title / footer 的函数声明属于 TableProps<TRecord>,插槽参数使用 TableDataSlotProps<TRecord>。props 为相关字段节选;TitleFooterFields、VTableSummaryProps 和 VTableSummaryCellProps 是文档辅助接口,不是包导出。VTableSummary.Row 没有自定义 props,完整声明见类型参考。
查看类型声明
/** TableProps 节选;文档辅助接口,不是包导出。 */
export interface TitleFooterFields<TRecord extends object = Record<string, any>> {
title?: (data: TRecord[]) => VNodeChild
footer?: (data: TRecord[]) => VNodeChild
}export interface TableDataSlotProps<TRecord extends object = Record<string, any>> {
data: TRecord[]
}export type SummaryFixed = boolean | 'top' | 'bottom'/** 文档说明用辅助接口,不是包导出。 */
export interface VTableSummaryProps {
fixed?: SummaryFixed
}/** 文档说明用辅助接口,不是包导出。index 是必填的列索引。 */
export interface VTableSummaryCellProps {
index: number
colSpan?: number
rowSpan?: number
align?: AlignType
}