预设与语言
这部分配置解决的是两个更上层的问题:
- 整体外观要贴近哪套 UI 体系。
- 表格内部文案要用哪种语言,以及如何局部覆盖。
在线示例
同一套列定义与数据,切换预设与语言看效果。这是本库最独特的一点:换皮肤不用换表格、不用换 API。
应用里一般直接
createVTableGuild({ themePreset })配一次即可。上面的示例为了在同一页对比两套皮肤,才就地 provide 了一个作用域 context。
主题预设
当前内置两套主题预设:
- antdv,默认预设,适合已经接入 ant-design-vue 的项目。
- element-plus,适合已经使用 element-plus 视觉体系的项目。
初始化时选择预设:
app.use(
createVTableGuild({
themePreset: 'antdv',
}),
)如果你改成 element-plus,直接在 JS 侧切换即可,无需追加 CSS(@vtable-guild/vtable-guild/css/style、@vtable-guild/vtable-guild/css/tailwind3 和 @vtable-guild/vtable-guild/css/tailwind4 均已内含所有预设样式):
app.use(
createVTableGuild({
themePreset: 'element-plus',
}),
)你不需要手动在 HTML 上添加 data-vtg-preset 属性,插件会自动处理。更多接入方式见 安装与使用。
内置语言
当前内置的 preset locale 至少覆盖了 zh-CN 和 en-US 两种常见语言场景,主要包括:
- 排序提示文案
- 筛选面板文案
- 空态文案
- 加载态文案
- 行选择菜单文案
- 分页、密度、列设置和工具栏文案
注册和覆盖语言包
如果你要切成英文或自定义文案,可以在插件层传 locale、locales 和 localeOverrides:
app.use(
createVTableGuild({
locale: 'en-US',
locales: {
'en-US': {
table: {
header: {
sortTriggerAsc: 'Sort ascending',
sortTriggerDesc: 'Sort descending',
cancelSort: 'Cancel sorting',
filterTriggerAriaLabel: 'Filter',
},
filterDropdown: {
searchPlaceholder: 'Search filters',
emptyText: 'No filters',
resetText: 'Reset',
confirmText: 'OK',
selectAllText: 'Select all',
},
empty: { text: 'No data' },
loading: { text: 'Loading...' },
selection: {
selectAll: 'Select all',
selectInvert: 'Invert selection',
selectNone: 'Clear selection',
selectionsTriggerAriaLabel: 'Selection options',
},
},
},
},
}),
)如果你只想覆盖少量字段,优先使用 localeOverrides,不必重写整套 locale。
selection.selectionsTriggerAriaLabel 是表头批量选择菜单入口的无障碍名称(读屏软件朗读的按钮名称),内置 选择操作 / Selection options。它是可选字段,旧语言包无需补齐,缺省时沿用内置文案。
局部作用域切换
当你需要在某个子树里覆盖语言或主题样式时,可以使用 VTableGuildConfigProvider:
<VTableGuildConfigProvider locale="en-US">
<VTable :columns="columns" :data-source="dataSource" />
</VTableGuildConfigProvider>这类方式适合局部对照页、多语言后台或嵌入式业务模块。
Provider 支持 theme、cssMode、classPrefix、locale、locales 和 localeOverrides,完整类型见页末声明。themePreset 与 compatClass 继承插件上下文;预设通过 createVTableGuild({ themePreset }) 配置,Provider 没有这两个 props。
相关页面
分页语言
语言包提供可选 pagination 分组,旧语言包无需修改。内置中英文;可用 localeOverrides.pagination 全局覆盖,或 pagination.locale 实例覆盖(最高优先级)。完整字段见 VTableGuildPaginationLocale;prev_pages / next_pages 是可选的跳转文案模板,{count} 会替换为跳转页数。
localeOverrides 支持深层局部覆盖,包括可选的 pagination、columnSettings 和 toolbar 分组,可以直接传少量字段。实例 pagination.locale 也支持局部覆盖。
import { createVTableGuild } from '@vtable-guild/vtable-guild'
app.use(
createVTableGuild({
localeOverrides: {
pagination: { items_per_page: '条记录 / 页' },
columnSettings: { reset: '恢复默认列' },
toolbar: { reload: '重新加载' },
},
}),
)工具栏与列设置语言
columnSettings 和 toolbar 也是可选语言分组,旧语言包无需补齐。内置中英文默认文案,跟随插件或 Provider 的 locale;使用 localeOverrides.columnSettings / localeOverrides.toolbar 覆盖全局文案。
VTableToolbar.locale 覆盖工具栏的刷新、全屏等文案,columnSettings.locale 覆盖内部列设置文案;单独使用 VTableColumnSettings 时直接传 locale。实例覆盖优先于全局配置。组件用法见 工具栏与业务扩展 和 列显示与列顺序。
Type Declarations
下列为本页使用的完整配置与语言声明。主题覆盖的依赖类型见 类型参考。Provider props 接口是文档辅助类型,不是包导出。
Type Declarations
export type ThemePresetName = 'antdv' | 'element-plus'export interface VTableGuildOptions {
themePreset?: ThemePresetName
cssMode?: VTableGuildCssMode
classPrefix?: string
theme?: VTableGuildThemeOverrides
locale?: LocaleName
locales?: LocaleRegistry
localeOverrides?: DeepPartial<VTableGuildLocale>
/** 安装时读取一次,不支持运行时切换。 */
compatClass?: boolean
}export declare function createVTableGuild(options?: VTableGuildOptions): Plugin/** 文档说明用辅助接口,不是包导出。描述 Provider 可传入的配置 props。 */
export interface VTableGuildConfigProviderProps {
theme?: VTableGuildThemeOverrides
cssMode?: VTableGuildCssMode
classPrefix?: string
locale?: LocaleName
locales?: LocaleRegistry
localeOverrides?: DeepPartial<VTableGuildLocale>
}export interface VTableGuildContext {
themePreset: ThemePresetName
cssMode: VTableGuildCssMode
classPrefix: string
theme: VTableGuildThemeOverrides
locale: LocaleName
locales: LocaleRegistry
localeOverrides: DeepPartial<VTableGuildLocale>
compatClass?: boolean
}export declare const VTABLE_GUILD_INJECTION_KEY: InjectionKey<VTableGuildContext>export type LocaleName = stringexport type BuiltInLocaleName = 'zh-CN' | 'en-US'export type LocaleRegistry = Record<LocaleName, VTableGuildLocale>export type DeepPartial<T> = {
[K in keyof T]?: NonNullable<T[K]> extends Array<infer U>
? Array<DeepPartial<U>>
: NonNullable<T[K]> extends object
? DeepPartial<T[K]>
: T[K]
}export interface VTableGuildLocale {
table: VTableGuildTableLocale
pagination?: VTableGuildPaginationLocale
columnSettings?: VTableGuildColumnSettingsLocale
toolbar?: VTableGuildToolbarLocale
selectionAlert?: VTableGuildSelectionAlertLocale
}export interface VTableGuildTableLocale {
tree?: { expand: string; collapse: string; retry: string }
cell?: {
copy: string
copied: string
copyFailed: string
edit?: string
clickToEdit?: string
cancelEdit?: string
}
header: VTableGuildTableHeaderLocale
filterDropdown: VTableGuildTableFilterDropdownLocale
empty: VTableGuildTableEmptyLocale
loading: VTableGuildTableLoadingLocale
selection: VTableGuildTableSelectionLocale
}export interface VTableGuildTableHeaderLocale {
sortTriggerAsc: string
sortTriggerDesc: string
cancelSort: string
filterTriggerAriaLabel: string
}export interface VTableGuildTableFilterDropdownLocale {
searchPlaceholder: string
emptyText: string
resetText: string
confirmText: string
selectAllText: string
}export interface VTableGuildTableEmptyLocale {
text: string
}export interface VTableGuildTableLoadingLocale {
text: string
}export interface VTableGuildTableSelectionLocale {
selectAll: string
selectInvert: string
selectNone: string
/** 表头批量选择菜单入口的无障碍名称;可选,旧语言包无需补齐。 */
selectionsTriggerAriaLabel?: string
}export interface VTableGuildPaginationLocale {
items_per_page: string
jump_to: string
jump_to_confirm: string
page: string
prev_page: string
next_page: string
prev_5: string
next_5: string
prev_3: string
next_3: string
/** {count} 会被替换为跳转页数。 */
prev_pages?: string
next_pages?: string
navigation: string
page_size: string
}export interface VTableGuildColumnSettingsLocale {
fixed?: string
fixedLeft?: string
fixedRight?: string
unfixed?: string
mixed?: string
move?: string
title: string
reset: string
density: string
large: string
middle: string
small: string
columns: string
empty: string
}export interface VTableGuildToolbarLocale {
searchPlaceholder?: string
search?: string
clearSearch?: string
label: string
reload: string
fullScreen: string
exitFullScreen: string
}export declare const paginationZhCN: VTableGuildPaginationLocale
export declare const paginationEnUS: VTableGuildPaginationLocale
export declare const elementPlusPaginationZhCN: VTableGuildPaginationLocale
export declare const elementPlusPaginationEnUS: VTableGuildPaginationLocale