最新研发uniapp+vue3跨端自定义表格table组件|uni-app增强版table
uni-vue3-table:基于uniapp+vue3全端通用自定义加强版table组件。支持固定表头/列、边框、斑马纹、单选/多选,自定义表头/表体内容插槽、左右固定列阴影高亮。支持编译运行web+小程序端+app端。
编译运行到H5+小程序+App端。
uni-vue3-table表格组件修复当列数过多,左右滚动会导致固定在左侧/右侧列也会随着一起滚动问题。
uniapp+vue3自定义表格
将uv3-table组件放在components目录,在页面template中即可直接使用。
- Props参数
- 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 无数据插槽
uni-vue3-table使用示例
- 模拟数据
<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>
- 基本用法
<uv3-table :columns="columns" :dataSource="data.list" />
- 自定义表格条纹/颜色、高度
<uv3-table:columns="columns":dataSource="data.list"stripestripeColor="#eee"padding="5px"height="300px" />
- 综合用法(固定左侧/右侧列、自定义表头/表体插槽、表格事件)
<uv3-table:dataSource="data.list":columns="columns":headerBold="true"headerBackground="#ecf5ff"stripeborderpadding="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>
uni-vue3-table表格组件已经更新到我的原创作品集。
uniapp+vue3跨端自定义table表格组件
综上就uniapp+vue3自定义表格组件的一些知识分享,感谢大家的阅读与支持。
附上几个最新项目实例
最新版uni-app+vue3+uv-ui跨三端仿微信app聊天应用【h5+小程序+app端】
Flutter3-MacOS桌面OS系统|flutter3.32+window_manager客户端OS模板
最新研发flutter3.27+bitsdojo_window+getx客户端仿微信聊天Exe应用
最新版uniapp+vue3+uv-ui跨三端短视频+直播+聊天【H5+小程序+App端】
Uniapp-DeepSeek跨三端AI助手|uniapp+vue3+deepseek-v3流式ai聊天模板
Electron35-DeepSeek桌面端AI系统|vue3.5+electron+arco客户端ai模板
vue3-webseek网页版AI问答|Vite6+DeepSeek+Arco流式ai聊天打字效果
flutter3-dymall仿抖音直播商城|Flutter3.27短视频+直播+聊天App实例
Tauri2.0+Vite5聊天室|vue3+tauri2+element-plus仿微信|tauri聊天应用
Electron32-ViteOS桌面版os系统|vue3+electron+arco客户端OS管理模板
Electron31-Vue3Admin管理系统|vite5+electron+pinia桌面端后台Exe