微信小程式中的列表切換功能例項程式碼詳解
阿新 • • 發佈:2020-06-11
感覺這列表切換有點類似於輪播圖,而且感覺這程式碼直接可以拿來用,稍微改一改樣式什麼的就OK了,列表切換也是用到的地方也很多
wxml中的程式碼如下:
<!-- 標籤頁面標題 --> <view class="tab"> <view class="tab-item {{tab==0?'active':''}}" bindtap="changeItem" data-item="0">音樂推薦</view> <view class="tab-item {{tab==1?'active':''}}" bindtap="changeItem" data-item="1">播放器</view> <view class="tab-item {{tab==2?'active':''}}" bindtap="changeItem" data-item="2">播放列表</view> </view> <!-- 內容 --> <view class="content"> <swiper current="{{item}}" bindchange="changeTab"> <swiper-item> <include src="info.wxml"/> </swiper-item> <swiper-item> <include src="player.wxml"/> </swiper-item> <swiper-item> <include src="playerlist.wxml"/> </swiper-item> </swiper> </view>
在js頁面的data中
wxss樣式:
.tab{ display: flex; } .tab-item{ flex: 1; font-size:10pt ; text-align: center; line-height: 72rpx; border-bottom: 6rpx solid #eee; } .content{ flex: 1; } .content>swiper{ height: 100%; } .tab-item.active{ color: #c25b5b; border-bottom-color:#c25b5b ; }
想設定這裡的樣式可以再.tab-item裡面
可以根據自己的審美設定 ,類似於下面這樣
總結
到此這篇關於微信小程式中的列表切換功能例項程式碼詳解的文章就介紹到這了,更多相關微信小程式列表切換內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!