微信小程序 tab切换展示不同的内容

本文介绍了一个使用微信小程序实现的保险产品分类展示界面,通过动态切换的Tab栏展示不同类型的保险产品,包括人身保障、财产保障、健康保障和养老保障。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

index.wxml

<view class='shopDetail-box'>
  <view class="tab-left" >
    <view class="{{tabArr.curHdIndex=='1'? 'active' : ''}}" id="1" data-id="1" bindtap="tab">人身保障</view>
    <view class="{{tabArr.curHdIndex=='2'? 'active' : ''}}" id="2" data-id="2" bindtap="tab">财产保障</view>
    <view class="{{tabArr.curHdIndex=='3'? 'active' : ''}}" id="3" data-id="3" bindtap="tab">健康保障</view>
    <view class="{{tabArr.curHdIndex=='4'? 'active' : ''}}" id="4" data-id="4" bindtap="tab">养老保障</view>
  </view>

  <view class="tab-right">
    <view class="right-item {{tabArr.curBdIndex=='1'? 'active' : ''}}">
   1
    </view>
    <view class="right-item {{tabArr.curBdIndex=='2'? 'active' : ''}}">
     2
    </view>
    <view class="right-item {{tabArr.curBdIndex=='3'? 'active' : ''}}">
     3
    </view>
    <view class="right-item {{tabArr.curBdIndex=='4'? 'active' : ''}}">
     4
    </view>
  </view>
</view>

index.wxss

.fs18{
  font-size: 18px;
}
.fs16{
  font-size: 16px;
}
.fs14{
  font-size: 14px;
}
.fs12{
  font-size: 12px;
}
.mb10{
  margin-bottom: 10px;
}
.shopDetail-box{
  padding-top: 55px;
}
.tab-left .active {
  color: #fc5b13;
  border-bottom: 2px solid #fc5b13;
}

.tab-left {
  background: #fff;
  position: fixed;
  z-index: 22;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
  color: #333;
  border-bottom: 1px solid #d5d5d5;
}

.tab-left view {
  width: 30%;
  height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.tab-right .right-item {
  display: none;
  height: 300rpx;
  width: 100%;
  /* border: solid 1px; */
}

.tab-right .right-item.active {
  display: block;
}

.shopDetail-bottom{
  position: absolute;
  left: 15px;
  bottom: 15px;
  color: #fff;
}

index.js

Page({
  data: {
    // tab 切换
    tabArr: {
      curHdIndex: 1,
      curBdIndex: 1
    }
  },
  //tab切换
  tab: function (e) {
    //var dataId = e.currentTarget.dataset.id;
    var dataId = e.currentTarget.id;
    var obj = {};
    obj.curHdIndex = dataId;
    obj.curBdIndex = dataId;
    this.setData({
      tabArr: obj
    })
    console.log(obj);
  },


})

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值