小程序实现轮点tab标签击选项卡切换页面

微信   2025-01-02 16:38   114   0  

31139_doui_8941.png

index.wxml

<view class="menu"> 
  <navigator wx:for="{{shouye}}"bindtap="change" class="{{page==index?'font-white':'font-black'}}" data-pageid="{{index}}">{{item}}</navigator>
</view>
<swiper current='{{page}}' bindchange="changepage">
  <swiper-item wx:for="{{shouye}}">
    <view class="view1">{{item}}</view>
  </swiper-item>
</swiper>


index.js

Page({
  data: {
    shouye: ['首页', '日程', '闹钟', '课程', '娱乐'],
    page: 0
  },
  change: function (event) {
    var a = event.currentTarget.dataset.pageid
    this.setData({
      page: a
    })
  },
  changepage: function (event) {
    console.log(event)
    var a = event.detail.current
    this.setData({
      page: a
    })
  }
})


index.wxss

/* pages/index/index.wxss */
scroll-view{
  width: 100%;
  height: 100%;
  display: flex;
}
.menu{
  background-color: red;
  display: flex;
  height: 60rpx;
  font-size: 40rpx;
  line-height: 70rpx;
  flex-direction: row;
  justify-content: space-around;
  
}
.font-white{
  border-bottom: 5rpx solid black;
  font-weight: bold;
}
.font-black{
}
.view1{
  height: 100%;
}


来源:https://www.freesion.com/article/6345624381/


博客评论
还没有人评论,赶紧抢个沙发~
发表评论
说明:请文明发言,共建和谐网络,您的个人信息不会被公开显示。