参数属性配置

参数属性配置

vol-table 通过 columns + tableData(或 url)驱动。direction 决定展示形态:

  • horizontal:表格形式(列宽、横向滚动、固定列、复选框等)
  • list:列表表单形式(内部复用 vol-form-item,字段能力与 vol-form 对齐)

兼容 H5 / App / 微信小程序。


组件属性

属性说明类型默认
directionhorizontal 表格 / list 列表Stringlist
url接口地址;配置后自动分页滚动加载String
tableData表格数据Array[]
columns列/字段配置Array[]
index是否显示行号(horizontal 更常用)Booleanfalse
ck是否显示复选框(仅 horizontal)Booleanfalse
height0=占满剩余高度;-1=内容自适应;其他=固定 pxNumber0
minHeight自动高度时的最小高度Number0
titleFieldlist 模式行标题字段String
readonly是否只读;list 编辑需设 falseBooleantrue
textInlinehorizontal 文本是否单行省略Booleantrue
textAlign文本对齐:left / center / rightString
labelWidthlist 标签宽度(px)Number0
labelPositionlist 标签位置:left / right / topString
loadKey是否自动加载字典Booleantrue
defaultLoad有 url 时是否默认加载Booleantrue
padding单元格内边距(也可 $global.table.padding)Number0
paddingBottom距底部距离(底部有自定义内容时)Number0
contentPadding外层有 padding 时参与高度计算Number0
rowStyle(row, index, rows) => style 行样式Function
columnStyle(row, column, index, rows) => style 单元格样式Function
selectable(row, column, rowIndex) => boolean 是否可选中Function
formatter / format表级单元格格式化Function
getButtonscolumn.btn 时返回按钮数组Function
loadBefore(params) => boolean 加载前;返回 false 中断Function
loadAfter(res) => boolean 加载后Function
getStyle / titleStyle / valueStylelist 标题与值样式Function/Object/String

全局可配:main.js → $global.table(如 border、padding、oddRowStyle、highlight、fontSize)。


columns 列配置

columns 为数组。list 模式元素还可以是:

  1. 普通字段 { title, field, type, ... }
  2. 分组 { type: 'group', title: '...' }
  3. 同行多列 [{...}, {...}]

通用 / horizontal

属性说明类型默认
title列标题 / 标签名String
field字段名String
width列宽 px(horizontal)Number
align对齐:center / right(跟随 textAlign)String
fixed固定列:left / right(仅 horizontal,CSS sticky)String
hiddentrue 隐藏;或 (row, item, rowIndex) => boolean 动态隐藏Boolean/Function
type见下方 type;horizontal 常用 date、img、select 等String
bind字典:{ key, data: [] }Object
slottrue 启用 #field(漏配则插槽不生效)Booleanfalse
headerSlottrue 启用 #columnHeaderBooleanfalse
headerFormatter(column, colIndex) => 文本或HTML 自定义表头Function
formatterhorizontal:(row, column, rowIndex) => HTML;list 只读:(val) => HTMLFunction
clicktrue 或函数;单元格可点Boolean/Function
btntrue 操作列,配合 props getButtonsBoolean
cellStyle(row, rowIndex, ...) => styleFunction
titleSlot / extraSlotlist:标题 / 右侧插槽开关Boolean
extra右侧文案或按钮,见 form 文档Object
readonly / required / range / min / max / url / multiple / maxCount 等list 编辑时与 vol-form 字段一致

type 常用值

场景type
文本/数字input、password、textarea、number、decimal、text
选择select、selectList、radio、checkbox、switch
日期date、datetime、time、month(可 range)
树/级联cascader、treeSelect、city
上传/图片img、file(list 上传;horizontal 的 img 为缩略图预览)
布局group

更多字段参数见 vol-form 参数。


数据插槽

只能使用固定插槽名。列上必须打开对应开关,否则不生效。禁止动态字段名插槽(小程序不支持)。

插槽启用条件data
#data存在即替代默认表格/列表渲染—
#columnHeaderheaderSlot: true{ field, column, colIndex }
#fieldslot: true{ field, row, column, rowIndex }
#customhorizontal 单元格追加(不替代默认内容)同上
#headerlist 行头{ row, rowIndex }
#titletitleSlot: true同 field
#extraextraSlot: true同 field
#bottomlist 行底{ row, rowIndex }
默认插槽表格底部自定义—
<template>
	<vol-table direction="horizontal" :columns="columns" :table-data="tableData">
		<template #columnHeader="{ data }">
			<view v-if="data.field === 'oper'">操作栏</view>
		</template>
		<template #field="{ data }">
			<view v-if="data.field === 'oper'">
				<vol-button size="small" type="primary" @click="viewClick(data)">查看</vol-button>
			</view>
		</template>
	</vol-table>
</template>
<script setup>
const columns = ref([
	{ field: 'OrderNo', title: '订单编号', width: 110 },
	{ field: 'oper', title: '操作', width: 140, slot: true, headerSlot: true }
])
</script>

完整示例见 格式化、样式、数据插槽、列表插槽。


事件 emit

事件说明参数
onChange下拉/日期/级联等变化(field, value, row, data?)
inputConfirm输入框回车(field, value, column, row, rowIndex, e)
onFocus / onKeyPress聚焦 / 按键结构类似
extraClickextra 按钮(item, row, index)
cellClick单元格点击(row, column, rowIndex, rows)
rowClick行点击(row, rowIndex, rows)
ckChange单行复选(row, isCK, index)
ckChangeAll全选(rows, isCK)
dicInited字典加载完成(dicData)
titleClick / valueClicklist 标题/值点击(item, row, rowIndex)

推荐:list 编辑事件写在 columns 字段上(与 web / vol-form 统一):

  • onChange: (value, item, row) => {}
  • onFocus / onKeyPress / inputConfirm / extraClick

组件标签 @xxx 仍兼容旧项目。


方法(ref)

方法说明
load(params?, reset?)刷新;reset=true 重置到第 1 页
getSelectedRows()获取选中行
clearSelectedRows()清除选中
delRows()删除选中行并返回被删数据
tableRef.value.load()
tableRef.value.load(null, true) // 重置分页
const rows = tableRef.value.getSelectedRows()

loadBefore 查询参数

与 Web 端查询前一致,常见:

const loadBefore = (params) => {
  params.wheres.push({
    name: 'OrderNo',
    value: orderNo.value,
    displayType: 'like'
  })
  return true // 返回 false 取消本次请求
}
Last Updated 2026/10/23 15:32:21