// wxml
class="swiper-tab">
<view class="swiper-tab-item {{currentTab==0?'active':''}}" data-index="0" bindtap="clickTab">1111view>
<view class="swiper-tab-item {{currentTab==1?'active':''}}" data-index="1" bindtap="clickTab">2222view>
view>
<swiper currrent="{{currentTab}}" class="swiper-box" duration="300" bindchange="swiperTab">
<swiper-item>
111111
swiper-item>
<swiper-item>
222222
swiper-item>
swiper>
// js
//滑动切换
swiperTab: function (e) {
var that = this;
console.log(e);
that.setData({
currentTab: e.detail.current
});
},
//点击切换
clickTab: function (e) {
//console.log(e);
let that = this;
that.setData({
currentTab: e.target.dataset.index
});
console.log("currentTab:"+that.data.currentTab);
}
预期:通过点击view(1111,2222)来让页面切换到不同swiper-item里显示
现在:点击view会更改currentTab的值,但是页面并没有切换,也不会触发bindchange;通过在swiper-item上滑动,页面会切换,也会触发bindchange
不知道是我的用法不对,还是又碰到个bug?
楼上大佬正解,提个优化,手动更改current的时候 判断下 source,以前遇到过有异常bug,不知道修复没。
打个广告:https://developers.weixin.qq.com/community/develop/article/doc/0004e6c4984ac84d74e8a47805b413
current 多了个 r