小程序实现Tab选项卡(Tab切换)

1,wxml代码结构

<view class="rech-list">

    <view class="{{0 == currentIndex ? 'rech-ac' : 'rech-view'}}" bindtap="titleClick" data-idx="0">

      <text class="rech-text1">个人会员</text>

      <text class="rech-num">2000积分</text>

      <text class="rech-mon">¥200.00</text>

    </view>

    <view class="{{1 == currentIndex ? 'rech-ac' : 'rech-view'}}" bindtap="titleClick" data-idx="1">

      <text class="rech-text1">普通会员</text>

      <text class="rech-num">10000积分</text>

      <text class="rech-mon">¥1000.00</text>

    </view>

    <view class="{{2 == currentIndex ? 'rech-ac' : 'rech-view'}}" bindtap="titleClick" data-idx="2">

      <text class="rech-text1">高级会员</text>

      <text class="rech-num">11000积分*5</text>

      <text class="rech-mon">¥5000.00</text>

    </view>

    <view class="{{3 == currentIndex ? 'rech-ac' : 'rech-view'}}" bindtap="titleClick" data-idx="3">

      <text class="rech-text1">VIP</text>

      <text class="rech-num">12000积分*5</text>

      <text class="rech-mon">¥15000.00</text>

    </view>

    <view style="clear:both;"></view>

  </view>

2,js代码

data: {

    //选择默认充值金额的索引值

    currentIndex:1,

  },

  //等级切换选项卡js代码

  titleClick: function (e) {

    let currentPageIndex =

      this.setData({

        //拿到当前索引并动态改变

        currentIndex: e.currentTarget.dataset.idx

      })

  },

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容