效果如下:可點(diǎn)擊切換,滑動(dòng)切換
代碼如下
這個(gè)可以在項(xiàng)目用
index.wxml
<view class='topTabSwiper'>
<view class='tab {{currentData == 0 ? "tabBorer" : ""}}' data-current = "0" bindtap='checkCurrent'>選項(xiàng)一</view>
<view class='tab {{currentData == 1 ? "tabBorer" : ""}}' data-current = "1" bindtap='checkCurrent'>選項(xiàng)二</view>
</view>
<swiper current="{{currentData}}" class='swiper' style="height:600px;" duration="300" bindchange="bindchange">
<swiper-item><view class='swiper_con'>TAB1</view></swiper-item>
<swiper-item><view class='swiper_con'>TAB2</view></swiper-item>
</swiper>
index.wxss文章來源:http://www.zghlxwxcb.cn/news/detail-625052.html
.tab {
width: 50%;
text-align: center;
padding: 10rpx 0;
}
.topTabSwiper {
display: flex;
justify-content: space-between;
}
.tabBorer {
border-bottom: 1px solid #f00;
color: #f00;
}
.swiper {
width: 100%;
}
.swiper_con {
text-align: center;
width: 100%;
height: 100%;
padding: 80rpx 0;
}
index.js文章來源地址http://www.zghlxwxcb.cn/news/detail-625052.html
//獲取當(dāng)前滑塊的index
bindchange:function(e){
const that = this;
that.setData({
currentData: e.detail.current
})
},
//點(diǎn)擊切換,滑塊index賦值
checkCurrent:function(e){
const that = this;
if (that.data.currentData === e.target.dataset.current){
return false;
}else{
that.setData({
currentData: e.target.dataset.current
})
}
},
到了這里,關(guān)于微信小程序選項(xiàng)卡切換(滑動(dòng)切換,點(diǎn)擊切換)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!