小程序实现tab栏目切换

一、效果图
在这里插入图片描述
二、代码
1、xml页面

<!-- 切换的tab栏 -->
  <view class="tab-container">
    <view
      class="default {{type=='plan'? 'type-active':''}}"
      bindtap="handleType"
      data-type="plan"
      >计划详情</view
    >
    <view
      class="default {{type=='internship'? 'type-active': ''}}"
      bindtap="handleType"
      data-type="internship"
      >实习任务</view
    >
  </view>
  <!-- 计划详情 -->
  <view wx:if="{{type=='plan'}}">
    1
  </view>

  <!-- 实习任务 -->
  <view wx:if="{{type=='internship'}}">
    2
  </view>

2、wxss

/* tab切换 */
.tab-container{
  display: flex;
  padding: 0 40rpx;
  width:670rpx;
  margin-top: 20rpx;
}
.default{
  font-size: 28rpx;
font-weight: 500;
color: #626262;
margin-right: 56rpx;
}
.type-active{
  color: #262626;
}

3、js

  data: {
    type:'plan',//控制tab切换
  },
  // 控制tab栏
  handleType(event) {
    const type = event.currentTarget.dataset.type;
    this.setData({
      type: type,
    });
  },

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值