微信小程序切换标签改变样式 - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 小程序相关 >

微信小程序切换标签改变样式

发表时间:2021-1-5

发布人:葵宇科技

浏览次数:35

wxml

<!--顶部导航栏-->
<view class="swiper-tab">
    <view class="tab-item {{currentTab==0 ? 'active' : ''}}" data-current="0" bindtap="swichNav">A</view>
    <view class="tab-item {{currentTab==1 ? 'active' : ''}}" data-current="1" bindtap="swichNav">B</view>
    <view class="tab-item {{currentTab==2 ? 'active' : ''}}" data-current="2" bindtap="swichNav">C</view>
</view>

<!--内容主体-->
<swiper class="swiper" current="{{currentTab}}" duration="400" bindchange="swiperChange">
    <block wx:for="{{tabs}}" wx:key="item">
        <swiper-item>
            <view>{{item}}</view>
        </swiper-item>
    </block>
</swiper>

wxss

.swiper-tab {
  display: flex;
  flex-direction: row;
  line-height: 60rpx;
  border-bottom: 2rpx solid #777;
}

.tab-item {
  width: 33.3%;
  text-align: center;
  font-size: 15px;
  color: rgb(235, 135, 135);
}

.swiper {
  width: 100%;
  font-size: 100rpx;
  height: 1140rpx;
  background: #dfdfdf;
}

.active {
  color: blue;
  border-bottom: 5rpx solid blue;
}

js

Page({
  data: {
    // tab切换
    currentTab: 0,
    tabs: ["A", "B", "C"],
  },
  swichNav: function (e) {
    // console.log(e);
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
      });
    }
  },
  swiperChange: function (e) {
    // console.log(e);
    this.setData({
      currentTab: e.detail.current,
    });
  },
});

相关案例查看更多