微信小程序標簽切換
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, }); }, });
如果您的問題還未解決可以聯系站長付費協助。

有問題可以加入技術QQ群一起交流學習
本站vip會員 請加入無憂模板網 VIP群(50604020) PS:加入時備注用戶名或昵稱
普通注冊會員或訪客 請加入無憂模板網 技術交流群(50604130)
客服微信號:15898888535
聲明:本站所有文章資源內容,如無特殊說明或標注,均為采集網絡資源。如若內容侵犯了原著者的合法權益,可聯系站長刪除。