Skip to content

BaseTable 基础表格

基于 Element Plus Table 封装的业务表格组件,简化表格配置,支持插槽自定义。

基础用法

通过 column 配置列信息,table-data 绑定数据源。

查看代码
vue
<template>
  <WxBaseTable :column="columns" :table-data="tableData" :loading="loading" />
</template>

<script setup>
import { ref } from 'vue'
import { WxBaseTable } from '@wangxing777/business'

const loading = ref(false)
const columns = [
  { prop: 'name', label: '姓名', width: 120 },
  { prop: 'age', label: '年龄', width: 80 },
  { prop: 'address', label: '地址' }
]
const tableData = [
  { name: '张三', age: 18, address: '北京市朝阳区' },
  { name: '李四', age: 22, address: '上海市浦东新区' }
]
</script>

自定义列

通过具名插槽自定义列内容,插槽名为列的 prop 值。

vue
<WxBaseTable :column="columns" :table-data="tableData">
  <template #name="{ row }">
    <span style="color: #409eff">{{ row.name }}</span>
  </template>
</WxBaseTable>

API

Props

属性说明类型默认值
column列配置BaseTableColumn[][]
tableData表格数据Array[]
loading加载状态booleanfalse
showOverflowTooltip内容过长时显示 tooltipbooleanfalse
selectionChange选择项改变时的回调(selection: unknown[]) => void-

BaseTableColumn

属性说明类型默认值
prop列字段名string-
label列标题string-
width列宽度number | string-
align对齐方式'left' | 'center' | 'right''center'
hidden是否隐藏booleanfalse

继承 Element Plus Table Column 的所有属性。

Slots

插槽名说明参数
toolButton表格上方工具栏-
[prop]自定义列内容{ row, column, $index }
header-[prop]自定义列表头-

Exposes

方法名说明参数
getSelectionRows获取选中行-
clearSelection清空选中项-
setCurrentRow设置当前行(row: unknown)
tableElement Plus Table 实例-

类型定义

typescript
import type { BaseTableColumn, BaseTableProps } from '@wangxing777/business'

基于 Vue 3 + Element Plus 的业务组件库