Taro+vue 微信小程序中使用原生table和样式

注意:head的数量与table-td中的数量一致,且字段顺序不能变,且width对应,且parent的width是子列宽度之和
在这里插入图片描述
在这里插入图片描述

<scroll-view :scroll-x="true">
        <view class="t-table">
          <view class="t-head">
            <view class="table-tr">
              <view
                v-for="(item, index) in tableConfig.head"
                :key="index"
                class="table-th"
                :style="{padding: !!item.parent ? '0' : '', width: item.width || item.parent.width}"
              >
                <template v-if="!item.parent">{{item.name}}</template>
                <template v-else>
                  <view>{{item.parent.name}}</view>
                  <view
                    v-for="(item2, index2) in item.child"
                    :key="index2"
                    class="table-th"
                    :style="{width: item2.width}"
                  >{{item2.name}}</view>
                </template>
              </view>
            </view>
          </view>

          <view class="t-body">
            <view
              v-for="(item, index) in tableData"
              :key="index"
              class="table-tr"
              :style="{backgroundColor: item.sort === '合计' ? '#FDF2F2' : item.isSum == '1' ? '#F4F9FF' : ''}"
            >
              <view class="table-td" style="width: 100px; color: rgba(0,0,0,0.5); fontSize: 14px">{{item.sort}}</view>
              <!-- <view class="table-td" style="width: 100px; color: rgba(0,0,0,0.5); fontSize: 14px">{{index + 1}}</view> -->
              <view class="table-td" style="width: 120px">{{item.a}}</view>
              <view class="table-td" style="width: 120px">{{item.a}}</view>
              <view class="table-td" style="width: 120px">{{item.a}}</view>
              <view class="table-td" style="padding: 0">
                <view class="table-td" style="width: 120px">{{item['合并列'].a}}</view>
                <view class="table-td" style="width: 120px">{{item['合并列'].b}}</view>
              </view>
              <view class="table-td" style="padding: 0">
                <view class="table-td" style="width: 130px">{{item.aa}}</view>
                <view class="table-td" style="width: 120px">{{item.bb}}</view>
              </view>
            </view>
          </view>
        </view>
tableConfig: {
        head: [
          {name: '序号', width: '100px'},
          {name: '时间', width: '120px'},
          {name: '名称', width: '120px'},
          {name: '地区', width: '120px'},
          {parent: {name: '合并列的title', width: '240px'},
            child: [{name: '子列1', width: '120px'},{name: '子列2', width: '120px'}]},
          {parent: {name: '合并列的title', width: '250px'}, child: [{name: '子列1', width: '130px'},{name: '子列2', width: '120px'},]},
        ]
      },
  scroll-view {
    white-space: nowrap;
    height: auto;
  }

 .t-table {
    display: table;
    width: 100%;
    border-collapse: collapse;
    // overflow-x: auto;
    margin-top: 20px;
    table-layout: fixed;
    box-sizing: border-box;
  }
  .t-head {
    display: table-header-group;
    font-size: 24px;
    color: rgba(0,0,0,0.5000);
    background-color: #F4F9FF;
    box-sizing: border-box;
  }
  .t-body {
    display: table-row-group;
    box-sizing: border-box;
  }
  .table-tr {
    display: table-row;
    width: 100%;
    height: 80px;
    line-height: 80px;
    text-align: center;
    box-sizing: border-box;
  }
  .table-th, .table-td {
    display: table-cell;
    min-width: 200px;
    font-size: 32px;
    padding: 20px;
    border: 1px solid #eee;
    text-align: center;
    vertical-align: middle;
    box-sizing: border-box;
  }
  .table-th {
    font-weight: 600;
  }
  .table-td {
    font-weight: 500;
    white-space: pre-wrap;
    line-height: normal;
    .table-td {
      border: none;
    }
  }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值