美文网首页
小程序表格

小程序表格

作者: _果不其然_ | 来源:发表于2019-06-13 09:43 被阅读0次

    实现效果1

    image.png

    WXML

    <view class="table">
      <view class="tr bg-w">
        <view class="th">head1</view>
        <view class="th">head2</view>
        <view class="th ">head3</view>
      </view>
      <block wx:for="{{listData}}" wx:key="{{code}}">
        <view class="tr bg-g" wx:if="{{index % 2 == 0}}">
          <view class="td">{{item.code}}</view>
          <view class="td">{{item.text}}</view>
          <view class="td">{{item.type}}</view>
        </view>
        <view class="tr" wx:else>
          <view class="td">{{item.code}}</view>
          <view class="td">{{item.text}}</view>
          <view class="td">{{item.type}}</view>
        </view>
      </block>
    </view>
    

    WXSS

    .table {
      border: 0px solid darkgray;
    }
    .tr {
      display: flex;
      width: 100%;
      justify-content: center;
      height: 3rem;
      align-items: center;
    }
    .td {
        width:40%;
        justify-content: center;
        text-align: center;
    }
    .bg-w{
      background: snow;
    }
    .bg-g{
      background: #E6F3F9;
    }
    .th {
      width: 40%;
      justify-content: center;
      background: #3366FF;
      color: #fff;
      display: flex;
      height: 3rem;
      align-items: center;
    }
    

    实现效果2

    image.png

    WXML

    <view id="panel" class="flex-column">
      <view class="flex-cell flex-row">
        <text class="flex-cell flex-row">1</text>
        <text class="flex-cell flex-row">2</text>
        <text class="flex-cell flex-row">3</text>
        <text class="flex-cell flex-row">4</text>
        
      </view>
      <view class="flex-row flex-cell">
        <text class="flex-cell flex-row">1</text>
        <text class="flex-cell flex-row">2</text>
        <text class="flex-cell flex-row">3</text>
        <text class="flex-cell flex-row">4</text>
      </view>
      <view class="flex-row flex-cell">
        <text class="flex-cell flex-row">1</text>
        <text class="flex-cell flex-row">2</text>
        <text class="flex-cell flex-row">3</text>
        <text class="flex-cell flex-row">4</text>
      </view>
      <view class="flex-row flex-cell">
        <text class="flex-cell flex-row">1</text>
        <text class="flex-cell flex-row">2</text>
        <text class="flex-cell flex-row">3</text>
        <text class="flex-cell flex-row">4</text>
      </view>
      <view class="flex-row flex-cell">
        <text class="flex-cell flex-row">1</text>
        <text class="flex-cell flex-row">2</text>
        <text class="flex-cell flex-row">3</text>
        <text class="flex-cell flex-row">4</text>
      </view>
    
    </view>
    

    WXSS

    #panel{
      height:auto;
      background:#fff;
    }
    #panel text{
      line-height: 9vh;
      border-right: 1rpx solid #ddd;
      border-bottom: 1rpx solid #ddd;
    }
    .flex-row{
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
    }
    .flex-column{
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: stretch;
    }
    .flex-cell{
      flex: 1;
    } 
    

    相关文章

      网友评论

          本文标题:小程序表格

          本文链接:https://www.haomeiwen.com/subject/rrqjfctx.html