增强版uniapp+vue3跨端自定义table组件

176 阅读3分钟

2025全新升级版uni-app+vue3自定义表格table组件|uniapp加强版table表格。

运行到小程序+web+app端。

未标题-1.png

uni-vue3-table支持固定表头/左右列、边框、表格条纹、单选/多选,自定义表头/表体内容插槽、左右固定列阴影。支持编译运行h5+小程序端+app端

p1.gif

p2.gif

修复列数过多,左右滚动会导致固定在左侧/右侧列也随着一起滚动问题。

360截图20250817065007444.png

uniapp+vue3表格组件

5242ccca42de3dc712a419dd9457a83f_1289798-20250817094612150-2054493682.png

  • props参数配置

ecc89ffa3dba7fcbea5268a170bac038_1289798-20250817095203903-420740136.png

  • columns参数
/**
 * 列参数
 * @params {string} background 对应列背景色
 * @params {string} type 对应列类型(多选selection 索引index)
 * @params {string} label 显示的列标题
 * @params {string} prop 对应的列字段名
 * @params {string} align 列水平对齐方式(left center right)
 * @params {number|string} width 对应列宽度
 * @params {boolean|string} fixed 该列固定到左侧(fixed:true|'left')或右侧(fixed:'right')
 * @params {string} columnStyle 对应列自定义样式
 * @params {string} className/class 表格列的类名className
 */
  • 表格事件
@headerClick 点击表头
@rowClick    点击行触发
@select    多选/单选
  • 表格自定义插槽
headerCell 自定义表头内容
default 默认表体内容
empty 无数据插槽

未标题-2.png

表格使用

p2-1.gif

  • 模拟数据
<script setup>
  import { ref } from 'vue'
  import Mock from 'mockjs'

  // 表格数据
  const data = ref(Mock.mock({
    total: 100,
    page: 1,
    pagesize: 10,
    'list|20': [
      {
        id: '@id()',
        author: '@cname()',
        title: '@ctitle(10, 50)',
        image: 'https://picsum.photos/400/400?random=' + '@guid()',
        switch: '@boolean()',
        'tags|1': ['admin', 'test', 'dev'],
        rate: '@integer(1, 5)',
        date: '@datetime()',
        color: '@color()',
      }
    ]
  }))

  // 表格列
  const columns = ref([
    {type: 'selection', align: 'center', width: 80, fixed: true}, // 多选
    {type: 'index', label: 'ID', align: 'center', width: 80, fixed: true}, // 索引序号
    {prop: 'author', label: '作者', align: 'center', width: 120},
    {prop: 'title', label: '标题', align: 'left', width: '350px'},
    {prop: 'image', label: '图片', align: 'center', width: '120px'},
    {prop: 'switch', label: '推荐', align: 'center', width: 100},
    {prop: 'tags', label: '标签', align: 'center', width: 100},
    {prop: 'rate', label: '评分', align: 'center', width: 200},
    {prop: 'date', label: '发布时间', align: 'left', width: '250px'}, // 时间
    {prop: 'date', label: '更新时间', align: 'left', width: '250px'}, // 时间
    {prop: 'action', label: '操作', align: 'center', width: 150, fixed: 'right'}, // 操作
  ])
</script>

003360截图20250816223247082.png

  • 基础使用
<uv3-table :columns="columns" :dataSource="data.list" />

005360截图20250816223502730.png

  • 自定义用法(表格边框/条纹/高度)
<uv3-table
  :columns="columns"
  :dataSource="data.list"
  stripe
  stripeColor="#eee"
  padding="5px"
  height="300px"
/>

M003360截图20250816231328348.png

M004360截图20250816231427212.png

  • 综合用法(固定列、自定义表头/内容插槽、事件)
<uv3-table
  :dataSource="data.list"
  :columns="columns"
  :headerBold="true"
  headerBackground="#ecf5ff"
  stripe
  border
  padding="5px"
  maxHeight="500px"
  @rowClick="handleRowClick"
  @select="handleSelect"
>
  <!-- 自定义header插槽内容 -->
  <template #headerCell="{ key, col, index }">
    <template v-if="key == 'title'">
      <view class="flex-c">{{col.label}} <input placeholder="搜索" /></view>
    </template>
    <template v-else-if="key == 'date'">
      <uni-icons type="calendar"></uni-icons> {{col.label}}
    </template>
    <template v-else>{{col.label}}</template>
  </template>

  <!-- 自定义body插槽内容(由于小程序不支持动态:name插槽,通过key标识l来自定义表格内容) -->
  <template #default="{ key, value, row, col, index }">
    <template v-if="key == 'image'">
      <uv-image :src="value" lazyLoad observeLazyLoad width="80rpx" height="80rpx" @click="previewImage(value)" />
    </template>
    <template v-else-if="key == 'switch'">
      <switch :checked="value" style="transform:scale(0.6);" />
    </template>
    <template v-else-if="key == 'tags'">
      <uv-tags :text="value" :color="row.color" :borderColor="row.color" plain size="mini" />
    </template>
    <template v-else-if="key == 'rate'">
      <uni-rate :value="value" size="14" readonly />
    </template>
    <template v-else-if="key == 'action'">
      <uni-icons type="compose" color="#00aa7f" @click="handleEdit(row)" />
      <uni-icons type="trash" color="#ff007f" style="margin-left: 5px;" @click="handleDel(row)" />
    </template>
    <template v-else>{{value}}</template>
  </template>
</uv3-table>

App003360截图20250817000247360.png

App004360截图20250817000932130.png

Ok,以上就是uni-app+vue3自定义表格组件的一些分享。

基于uni-app+vue3+uvui跨三端仿微信app聊天模板

基于flutter3.32+window_manager仿macOS/Wins风格桌面os系统

flutter3.27+bitsdojo_window电脑端仿微信Exe应用

基于uniapp+vue3+uvue短视频+聊天+直播app系统

基于uniapp+vue3+deepseek+markdown搭建app版流式输出AI模板

vue3.5+deepseek+arco+markdown搭建web版流式输出AI模板

Flutter3.x深度融合短视频+直播+聊天app实例

自研tauri2.0+vite6.x+vue3+rust+arco-design桌面版os管理系统Tauri2-ViteOS

自研tauri2.0+vite5+vue3+element-plus电脑版exe聊天系统Vue3-Tauri2Chat

原创electron31+vite5.x+elementPlus桌面端后台管理系统

Vite5-Electron-Wechat聊天实例|electron31+vue3客户端聊天EXE