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
    评论
微信小程序,我们可以使用下拉刷新组件来刷新页面。在 Taro + Vue3 ,可以通过在页面的配置对象添加 `enablePullDownRefresh: true` 来启用下拉刷新功能。 具体步骤如下: 1. 在页面的配置对象添加 `enablePullDownRefresh: true`。 ```javascript export default { enablePullDownRefresh: true, // ... } ``` 2. 在页面的方法添加 `onPullDownRefresh` 方法,该方法会在用户下拉刷新时触发。 ```javascript export default { enablePullDownRefresh: true, onPullDownRefresh() { // 执行刷新操作 }, // ... } ``` 3. 在 `onPullDownRefresh` 方法编写刷新操作的代码。例如,我们可以重新请求数据,并更新页面渲染。 ```javascript export default { enablePullDownRefresh: true, async onPullDownRefresh() { // 重新请求数据 const newData = await this.fetchData() // 更新页面渲染 this.dataList = newData // 停止下拉刷新 Taro.stopPullDownRefresh() }, // ... } ``` 4. 最后,在页面添加下拉刷新组件。可以使用 Taro UI 的 `AtPullDownRefresh` 组件,也可以自定义组件。 ```html <template> <!-- 使用 Taro UI 的 AtPullDownRefresh 组件 --> <view> <at-pull-down-refresh v-model="isRefreshing" color="#999" background-color="#f7f7f7" bind:refresh="onPullDownRefresh" > <view class="status" slot="status"> {{ isRefreshing ? '正在刷新...' : '下拉刷新' }} </view> </at-pull-down-refresh> <!-- 渲染数据列表 --> <view v-for="item in dataList" :key="item.id"> {{ item.title }} </view> </view> </template> ``` 以上就是在 Taro + Vue3 实现微信小程序下拉刷新的方法。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值