在作H5開發中表格table是最多見的標籤,如此好用的標籤在微信小程序中卻沒有,無奈,嘆息,絕望!!!html
奔着利國利猿的使命,我***開始了造輪之路。前端
主要用於展現大量結構化數據。git
支持分頁、自定義操做、長,寬表格滾動等功能。github
前言json
細節小程序
Component({
properties: {
list: { // 表格數據
type: Array,
value: []
},
headers: { //表頭
type: Array,
value: []
},
hasBorder: { // 表格中間邊框
type: String,
value: "no"
},
height: { //table的高度
type: Number || String,
value: ''
},
width: {
type: Number,
value: 0
},
tdWidth: {
type: Number,
value: 35
}
}
})
複製代碼
/*
s-class-header // 外部定義表頭樣式
s-class-row // 外部定義行數據樣式
*/
Component({
externalClasses: ['s-class-header', 's-class-row']
})
複製代碼
<view class="table table-noborder">
<view class="tr thead s-class-header">
<view wx:for="{{headers}}" class="td td-{{hasBorder}}border">{{item.display}}</view>
</view>
<block wx:for-item='i' wx:for="{{list}}">
<view class="tr s-class-row">
<view wx:for-item='j' wx:for="{{headers}}" class="td td-{{hasBorder}}border">{{i[j['text']]}}</view>
</view>
</block>
</view>
複製代碼
.table {
border: 1px solid #ccc;
font-size: 28rpx;
background: #fff;
border-right:none;
}
.table-noborder {
border-right:1rpx solid #ccc;
}
.tr{
display: flex;
}
.td {
text-align: center;
border: 1px solid #ccc;
display: inline-block;
border-bottom: none;
flex: 1;
padding: 16rpx;
border-left: none;
}
.td-noborder{
border-right: none;
}
.thead .td{
border-top: none;
padding: 16rpx;
font-weight: bold;
}
複製代碼
.json文件引入組件微信小程序
{
"usingComponents": {
"s-table": "實際路徑/table/index"
}
}
複製代碼
index.wxml 文件使用組件bash
<s-table hasBorder='no' width='200' tdWidth='100' height='200' s-class-header='my-class' s-class-row='my-class-row' headers='{{headers}}' list='{{row}}'></s-table>
複製代碼
github地址微信
快狗打車前端團隊專一前端技術分享,按期推送高質量文章,歡迎關注點贊。 文章同步發佈在公衆號喲,想要第一時間獲得最新的資訊,just scan it !app