Skip to content

注册自定义组件

通过 tableComponentRegistry.register 注册一次,全局可用:

ts
import { tableComponentRegistry } from '@/components/XTable'
import MyBadge from './MyBadge.vue'

tableComponentRegistry.register({
  type: 'my-badge',
  component: MyBadge,
})

在列配置中通过 componentType: 'my-badge' 引用即可:

ts
const columns: ColumnConfig<User>[] = [
  {
    prop: 'level',
    label: '等级',
    componentType: 'my-badge',
    componentProps: (row) => ({
      value: row.level,
      color: row.level > 5 ? 'gold' : 'silver',
    }),
  },
]

内置组件

XTable 内置支持所有 Element Plus 组件(如 el-tagel-switchel-button 等),可直接在 componentType 中使用,无需额外注册。

ts
// 使用 el-tag
{ prop: 'status', label: '状态', componentType: 'el-tag' }

// 使用 el-switch
{ prop: 'active', label: '启用', componentType: 'el-switch' }

// 使用 el-button
{ prop: 'action', label: '操作', componentType: 'el-button' }

Released under the MIT License.