微信小程序制作表格

本文介绍了如何在微信小程序中创建表格。通过提供WXML页面设计代码和WXSS样式布局代码,展示了如何构建一个简单的表格,包括行和单元格的设置,以及边框和填充颜色的样式处理。
摘要由CSDN通过智能技术生成

一.页面wxml设计代码:

 

<view class="container" bindtouchstart='containerTap1'>

<view class="table" >

<view class="tr" wx:for="{ {1}}">

<view class='td' bindtap="XiuXian" style='background-color:{ {TbBackgroundColor}}'> 休闲</view>

<view class="td"> 益智</view>

</view>

<view class="tr" wx:for="{ {1}}">

<view class='td'> 技能</view>

<view class="td"> 直播</view>

</view>

<view class="tr" wx:for="{ {1}}">

<view class='td'> 运动</view>

<view class="td"> 体育</view>

</view>

</view>

</view>

二.样式wxss布局代码

制作一个表格,需要用到小程序的<scroll-view>、<view>、<text>等组件。 以下是一个简单的例子: 1. 在wxml中编写表格的结构: ``` <scroll-view class="table-container"> <view class="table-header"> <text class="table-cell">姓名</text> <text class="table-cell">年龄</text> <text class="table-cell">性别</text> </view> <view class="table-row"> <text class="table-cell">小明</text> <text class="table-cell">18</text> <text class="table-cell">男</text> </view> <view class="table-row"> <text class="table-cell">小红</text> <text class="table-cell">20</text> <text class="table-cell">女</text> </view> </scroll-view> ``` 2. 在wxss中编写表格的样式: ``` .table-container { height: 300rpx; width: 100%; border: 1rpx solid #ccc; overflow: scroll; } .table-header { display: flex; flex-direction: row; justify-content: space-between; background-color: #f5f5f5; border-bottom: 1rpx solid #ccc; } .table-row { display: flex; flex-direction: row; justify-content: space-between; border-bottom: 1rpx solid #ccc; } .table-cell { width: 33.3%; text-align: center; } ``` 3. 在js中添加数据: ``` Page({ data: { tableData: [ {name: "小明", age: 18, gender: "男"}, {name: "小红", age: 20, gender: "女"} ] } }) ``` 4. 在wxml中使用数据渲染表格: ``` <scroll-view class="table-container"> <view class="table-header"> <text class="table-cell">姓名</text> <text class="table-cell">年龄</text> <text class="table-cell">性别</text> </view> <view wx:for="{{tableData}}" wx:key="index" class="table-row"> <text class="table-cell">{{item.name}}</text> <text class="table-cell">{{item.age}}</text> <text class="table-cell">{{item.gender}}</text> </view> </scroll-view> ``` 这样就可以制作一个简单的表格了。你可以根据自己的需求,对表格进行进一步的美化和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值