在作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