uniapp、微信小程序--自定义table

啥先不说直接看效果吧

最开始是用Uview写的表格 但是发现属性太少了,首先就是不能取消横竖边框,最后就是没有办法改变每一行的背景颜色,他只有th-style改变表头的背景颜色

然后我选择用uni-ui的表格组件,发现他可以取消竖的边框 但是还是不能改变每一行的背景颜色,

使用deep穿透也不行,

最后采用view原生写法

<view class="table">
					<view class="tr">
						<view class="th">序号</view>
						<view class="th">名称</view>
						<view class="th">次数</view>
						<view class="th">通过率</view>
					</view>
					<view class="tr" style="">
						<view class="td">
							<image src="../../static/slices/first.png" style="width: 89rpx;height: 61rpx; margin-left: -59rpx;margin-top: -8rpx; position: absolute;"></image>
						</view>
						<view class="td">张飒</view>
						<view class="td">12</view>
						<view class="td">100%</view>
					</view>
					<view class="tr">
						<view class="td" >
							<image src="../../static/slices/second.png" style="width: 89rpx;height: 61rpx; margin-left: -59rpx;margin-top: -8rpx;position: absolute;"></image>						
						</view>
						<view class="td">李斯</view>
						<view class="td">8</view>
						<view class="td">100%</view>
					</view>
					<view class="tr">
						<view class="td">
							<image src="../../static/slices/third.png" style="width: 89rpx;height: 61rpx; margin-left: -59rpx;margin-top: -8rpx;position: absolute;"></image>
						</view>
						<view class="td">王武</view>
						<view class="td">7</view>
						<view class="td">100%</view>
					</view>
					<view class="tr">
						<view class="td">4</view>
						<view class="td">王二</view>
						<view class="td">6</view>
						<view class="td">100%</view>
					</view>
					<view class="tr">
						<view class="td">5</view>
						<view class="td">麻子</view>
						<view class="td">3</view>
						<view class="td">100%</view>
					</view>
				</view>
.table {
						width: 100%;
						border-radius: 8rpx;
						display: table;
						border: 1px solid #EFEFEF;
						border-collapse: collapse;
						font-size: 28rpx;
						.th {
							text-align: center;
							color: #333333;
							padding: 20rpx 0;
							font-weight: bolder;
							display: table-cell;
						}
						.td {
							text-align: center;
							padding: 20rpx 0;
							display: table-cell;
						}			 
						.tr {
							display: table-row;
						}
					}
					.table .tr:nth-child(1){
						background-color: #F4F4F4 ;
					}
					.table .tr:nth-child(2){
						background: linear-gradient(270deg, #FFFFFF 0%, #FFF4E8 100%);
					}
					.table .tr:nth-child(3){
						background: linear-gradient(270deg, #FFFFFF 0%, #E8F3FF 100%);
					}
					.table .tr:nth-child(4){
						background: linear-gradient(270deg, #FFFFFF 0%, #FFEFF2 100%);
					}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
对于uniapp微信小程序,你可以通过自定义组件来实现自定义tabbar。以下是一种实现方法: 1. 在 uniapp 项目中创建一个新的自定义组件,例如 "custom-tabbar"。 2. 在 custom-tabbar 组件的文件夹中,创建一个 JSON 文件,命名为 "custom-tabbar.json"。在该文件中定义组件使用的自定义属性,例如: ```json { "component": true, "usingComponents": {} } ``` 3. 在 custom-tabbar 组件的文件夹中,创建一个 WXML 文件,命名为 "custom-tabbar.wxml"。在该文件中编写自定义tabbar的布局,例如: ```html <view class="custom-tabbar"> <!-- 自定义的tabbar按钮 --> <view class="custom-tabbar-item" bindtap="navigateToPage"> <!-- 按钮图标 --> <image src="{{ activeIndex === 0 ? 'icon1-active' : 'icon1' }}"></image> <!-- 按钮文字 --> <text class="{{ activeIndex === 0 ? 'active' : '' }}">Tab1</text> </view> <view class="custom-tabbar-item" bindtap="navigateToPage"> <!-- 按钮图标 --> <image src="{{ activeIndex === 1 ? 'icon2-active' : 'icon2' }}"></image> <!-- 按钮文字 --> <text class="{{ activeIndex === 1 ? 'active' : '' }}">Tab2</text> </view> <!-- 更多按钮 --> <view class="custom-tabbar-item more" bindtap="showMoreOptions"> <!-- 更多按钮图标 --> <image src="more-icon"></image> </view> </view> ``` 4. 在 custom-tabbar 组件的文件夹中,创建一个 WXSS 文件,命名为 "custom-tabbar.wxss"。在该文件中编写自定义tabbar的样式,例如: ```css .custom-tabbar { display: flex; align-items: center; height: 50px; background-color: #fff; } .custom-tabbar-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; } .custom-tabbar-item image { width: 30px; height: 30px; } .custom-tabbar-item text { font-size: 12px; margin-top: 5px; } .custom-tabbar-item.more { position: relative; } .custom-tabbar-item.more image { width: 40px; height: 40px; } .active { color: #007aff; } ``` 5. 在需要使用自定义tabbar的页面中,引入 custom-tabbar 组件,例如: ```html <template> <view> <!-- 页面内容 --> </view> <!-- 引入自定义tabbar组件 --> <custom-tabbar></custom-tabbar> </template> <script> import customTabbar from '@/components/custom-tabbar/custom-tabbar' export default { components: { customTabbar }, // 页面逻辑代码 } </script> <style> /* 页面样式 */ </style> ``` 通过以上步骤,你就可以在uniapp微信小程序中实现自定义tabbar了。你可以根据自己的需求修改自定义tabbar的布局和样式,以及处理相应的点击事件。希望能对你有所帮助!
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值