基于uniapp+vue3自定義增強(qiáng)版table表格組件「兼容H5+小程序+App端」
uv3-table:一款基于uniapp+vue3跨端自定義手機(jī)端增強(qiáng)版表格組件。支持固定表頭/列、邊框、斑馬紋、單選/多選,自定義表頭/表體插槽、左右固定列陰影高亮顯示。支持編譯兼容H5+小程序端+App端。
如下圖:H5+小程序+App端,多端運(yùn)行一致。
uv3-table表格插件是最新原創(chuàng)項(xiàng)目uniapp-os后臺(tái)管理系統(tǒng)的一個(gè)獨(dú)立版組件。
由于在開(kāi)發(fā)uni-os手機(jī)后臺(tái)系統(tǒng)需要用到table表格組件。無(wú)奈uniapp官方及插件市場(chǎng)table表格組件無(wú)論功能及UI上都不滿足要求,于是自己爆肝一個(gè)多日夜開(kāi)發(fā)了一款全新uniapp+vue3綜合表格組件。
目前該項(xiàng)目已經(jīng)出階段性成果接近尾聲了,相信很快就能和大家見(jiàn)面,到時(shí)也會(huì)做一些技術(shù)分享,敬請(qǐng)期待!
uv3-table使用示例
將uv3-table組件放到uniapp項(xiàng)目components目錄下,無(wú)需在頁(yè)面再次引入,即可使用。
基礎(chǔ)用法
<uv3-table :columns="columns" :dataSource="data.list" />
自定義條紋樣式
<uv3-table :columns="columns" :dataSource="data.list" stripe stripeColor="#eee" padding="5px" height="450rpx" />
綜合用法(固定表頭/列、自定義插槽內(nèi)容)
<script setup> import { ref } from 'vue' import Mock from 'mockjs' const columns = ref([ {type: 'selection', align: 'center', width: 80, fixed: true}, // 多選 {type: 'index', label: 'ID', align: 'center', width: 80, fixed: true}, // 索引序號(hào) {prop: 'author', label: '作者', align: 'center', width: 120}, {prop: 'title', label: '標(biāo)題', align: 'left', width: 350}, {prop: 'image', label: '圖片', align: 'center', width: 120}, {prop: 'switch', label: '推薦', align: 'center', width: 100}, {prop: 'tags', label: '標(biāo)簽', align: 'center', width: 100}, {prop: 'rate', label: '評(píng)分', align: 'center', width: 200}, {prop: 'date', label: '發(fā)布時(shí)間', align: 'left', width: 250}, // 時(shí)間 {prop: 'action', label: '操作', align: 'center', width: 150, fixed: 'right'}, // 操作 ]) const data = ref(Mock.mock({ total: 100, page: 1, pagesize: 10, 'list|20': [ { id: '@id()', author: '@cname()', title: '@ctitle(10, 20)', image: `//api.yimian.xyz/img?id=@integer(100, 300)`, switch: '@boolean()', 'tags|1': ['admin', 'test', 'dev'], rate: '@integer(1, 5)', date: '@datetime()', color: '@color()', } ] })) </script>
<uv3-table :dataSource="data.list" :columns="columns" :headerBold="true" headerBackground="#ecf5ff" stripe border padding="5px" maxHeight="650rpx" @rowClick="handleRowClick" @select="handleSelect" > <!-- 自定義header插槽內(nèi)容 --> <template #headerCell="{ key, col, index }"> <template v-if="key == 'title'"> <view >{{col.label}} <input placeholder="搜索" size="small" /></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插槽內(nèi)容(由于小程序不支持動(dòng)態(tài):name插槽,通過(guò)key標(biāo)識(shí)來(lái)自定義表格內(nèi)容) --> <template #default="{ key, value, row, col, index }"> <template v-if="key == 'image'"> <uv-image :src="value" lazyLoad observeLazyLoad @click="previewImage(value)" /> </template> <template v-else-if="key == 'switch'"> <switch :checked="value" /> </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" @click="handleDel(row)" /> </template> <template v-else>{{value}}</template> </template> </uv3-table>
rowClick點(diǎn)擊表格行,會(huì)返回該行數(shù)據(jù)。
select單選/多選,會(huì)返回表格選中數(shù)據(jù)。
uv3Table編碼實(shí)現(xiàn)
uv3-table表格參數(shù)配置
const props = defineProps({ // 表格數(shù)據(jù) dataSource: { type: Array, default() { return [] } }, /** * @params {string} background 對(duì)應(yīng)列背景色 * @params {string} type 對(duì)應(yīng)列類型(多選selection 索引index) * @params {string} label 顯示的列標(biāo)題 * @params {string} prop 對(duì)應(yīng)的列字段名 * @params {string} align 列水平對(duì)齊方式(left center right) * @params {number|string} width 對(duì)應(yīng)列寬度 * @params {boolean|string} fixed 該列固定到左側(cè)(fixed:true|'left')或右側(cè)(fixed:'right') * @params {string} columnStyle 對(duì)應(yīng)列自定義樣式 * @params {string} className/class 表格列的類名className */ columns: { type: Array, default() { return [] } }, // 表格寬度 width: { type: [Number, String] }, // 表格高度 height: { type: [Number, String] }, // 表格最大高度 maxHeight: { type: [Number, String] }, // 是否為斑馬紋 stripe: { type: [Boolean, String] }, // 斑馬紋背景 stripeColor: { type: String, default: '#fafafa' }, // 是否帶有邊框 border: { type: [Boolean, String] }, // 列寬度(推薦默認(rèn)rpx) columnWidth: { type: [Number, String], default: 200 }, // 單元格間距 padding: { type: String, default: '5rpx 10rpx' }, // 是否顯示表頭 showHeader: { type: [Boolean, String], default: true }, // 表頭背景色 headerBackground: { type: String, default: '#ebeef5' }, // 表頭顏色 headerColor: { type: String, default: '#333' }, // 表頭字體加粗 headerBold: { type: [Boolean, String], default: true }, // 表格背景色 background: { type: String, default: '#fff' }, // 表格顏色 color: { type: String, default: '#606266' }, // 空數(shù)據(jù)時(shí)顯示的文本內(nèi)容,也可以通過(guò) #empty 設(shè)置 emptyText: { type: String, default: '暫無(wú)數(shù)據(jù)' } })
模板結(jié)構(gòu)如下
<template> <view ... > <!-- 表頭 --> <view v-if="showHeader" :> <view v-for="(col, cindex) in columns" :key="cindex" : ... @click="handleHeaderClick(col)" > ... </view> </view> <!-- 表體 --> <view > ... </view> </view> </template>
Props參數(shù)
columns參數(shù)
background 對(duì)應(yīng)列背景色 type 對(duì)應(yīng)列類型(多選selection 索引index) label 顯示的列標(biāo)題 prop 對(duì)應(yīng)的列字段名 align 列水平對(duì)齊方式(left center right) width 對(duì)應(yīng)列寬度 fixed 該列固定到左側(cè)(fixed:true|‘left’) 或 右側(cè)(fixed:‘right’) columnStyle 對(duì)應(yīng)列自定義樣式 className/class 表格列的類名className
事件
@headerClick 點(diǎn)擊表頭 @rowClick 點(diǎn)擊行觸發(fā) @select 多選/單選
自定義插槽
headerCell 自定義表頭內(nèi)容 default 默認(rèn)表體內(nèi)容 empty 無(wú)數(shù)據(jù)插槽
希望以上分享對(duì)大家有些幫助,開(kāi)發(fā)不易,一起fighting~~??
到此這篇關(guān)于基于uniapp+vue3自定義增強(qiáng)版table表格組件「兼容H5+小程序+App端」的文章就介紹到這了,更多相關(guān)uniapp+vue3自定義增強(qiáng)版table表格組件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
VUE DEMO之模擬登錄個(gè)人中心頁(yè)面之間數(shù)據(jù)傳值實(shí)例
今天小編就為大家分享一篇VUE DEMO之模擬登錄個(gè)人中心頁(yè)面之間數(shù)據(jù)傳值實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10Vue中使用localStorage存儲(chǔ)token并設(shè)置時(shí)效
這篇文章主要為大家介紹了Vue中使用localStorage存儲(chǔ)token并設(shè)置時(shí)效,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06詳解Vue如何進(jìn)行表單聯(lián)動(dòng)與級(jí)聯(lián)選擇
表單聯(lián)動(dòng)和級(jí)聯(lián)選擇是Vue.js中常見(jiàn)的功能,在下面的文章中,我們將討論如何在Vue.js中實(shí)現(xiàn)表單聯(lián)動(dòng)和級(jí)聯(lián)選擇,感興趣的小伙伴可以了解一下2023-06-06如何正確解決VuePress本地訪問(wèn)出現(xiàn)資源報(bào)錯(cuò)404的問(wèn)題
這篇文章主要介紹了如何正確解決VuePress本地訪問(wèn)出現(xiàn)資源報(bào)錯(cuò)404的問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12vue實(shí)現(xiàn)列表無(wú)縫滾動(dòng)
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)列表無(wú)縫滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06