微信小程序制作表格

 

  <div class="tb-body">
    <div class="tb-head">
      <div class="th">标题一</div>
      <div class="th">标题一</div>
      <div class="th">标题一</div>
      <div class="th">标题一</div>
      <div class="th">标题一</div>
      <div class="th">标题一</div>
      <div class="th">标题一</div>
    </div>
    <div v-for="(item,index) in listData" class="tb-data">
      <div class="td">{{ item.id}}</div>
      <div class="td">{{ item.name}}</div>
      <div class="td">{{ item.test}}</div>
      <div class="td">{{ item.id}}</div>
      <div class="td">{{ item.name}}</div>
      <div class="td">{{ item.test}}</div>
      <div class="td">{{ item.test}}</div>
    </div>
  </div>
.tb-body {
  overflow-x: auto;
  white-space: nowrap;
  word-break: keep-all;

  .tb-head {
    color: #909090;
  }

  .tb-head, .tb-data {
    display: table-row;
    text-align: center;
  }

  .tb-head .th, .tb-data .td {
    display: table-cell;
    padding: 5px 10px;
    border-bottom: 1px solid #EBEBEB;
  }

}

制作一个表格,需要用到小程序的<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、付费专栏及课程。

余额充值