Skip to content
On this page

table组件

https://element-plus.org/zh-CN/component/table.html

Hidden Title

all

基础用法

other

单选

多选

多级表头

隐藏按钮或列 isShow

通常用法

编辑

reConfirm再确认

表格里嵌套表格

render生成html

改变操作按钮的属性

对比

属性

属性名说明类型默认值
data表格数据源array[]
columns列配置array[]
showPage是否显示分页booleantrue
showIndex是否显示序号列booleantrue
pageSize每页条数number30
pageNumber当前页码number1
pageSizes分页器可选每页条数array[10, 30, 50]
total总条数,不传时默认取 data.lengthnumber-
columnEmptyText单元格空值占位文案string-
loading表格加载状态booleanfalse
indexAttrs序号列透传给 el-table-column 的配置object{}
modelValue选中值;单选时为当前行,多选时为选中行数组any-
selectionType内置选中模式,支持 single / multiplestring''
selectionAttrs内置单选列/多选列透传配置object{}
asyncUpdate是否由外部异步控制分页状态booleanfalse
pageAttrs分页组件透传配置object{}

事件

事件名说明回调参数
page-change页码或每页条数变化时触发({ pageNumber, pageSize })
update:modelValue内置单选/多选值变化时触发(selectedRow | selectedRows)

columns 常用字段

字段名说明类型
label列标题string
prop对应字段名string
type特殊列类型,如 selection / expandstring
width列宽string / number
fixed固定列string / boolean
align对齐方式string
useSlot使用插槽渲染,传 true 时默认插槽名为 propboolean / string
render自定义渲染函数function
filter自定义文本处理function
handler单元格点击事件function
isShow控制列是否显示,支持布尔值或函数boolean / function
columnEmptyText当前列的空值占位文案,会覆盖全局 columnEmptyTextstring
btns操作栏按钮配置,存在时该列作为操作列渲染array
maxBtns操作栏最多显示的总数量,包含“更多”入口,默认 4number

render 参数

render 统一接收一个对象参数:

ts
render({ row, scope, value, column, action, index })
render({ row, scope, value, column, action, index })
参数名说明
row当前行数据
scopeel-table-column 默认插槽作用域
value当前列 prop 对应的值;操作按钮未配置 prop 时可能为 undefined
column当前列配置对象
action当前操作按钮配置对象,仅操作栏下存在
index当前行索引,对应 scope.$index

回调参数

filterhandlerisShowdisabledreConfirm,以及按钮的 content / title 函数,推荐统一使用对象参数:

ts
const callback = ({ row, scope, value, column, action, index, event }) => {}
const callback = ({ row, scope, value, column, action, index, event }) => {}
  • value 是当前列或当前按钮 prop 对应的值。
  • event 仅点击相关回调下存在。
  • 仍兼容旧的位置参数写法,但更推荐对象写法,和 render 保持一致。

说明

  • 组件底层基于 el-tableel-pagination 封装,未在上表列出的表格属性可继续通过 attrs 透传。
  • asyncUpdatetrue 时,分页切换只触发 page-change 事件,由外部维护 pageNumberpageSize
  • 操作栏 maxBtns 默认值为 4,表示总共最多显示 4 个槽位;当按钮数量超出时,会显示 maxBtns - 1 个按钮加一个“更多”入口。
  • 单选推荐直接用 v-model + selection-type="single";多选推荐直接用 v-model + selection-type="multiple",如果要跨页保留选中项,记得传 row-key