收藏
回答

swiper 手动设置current属性,页面不会切换,滑动时页面才会切换,是bug吗?

// 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
        });
    },
    //点击切换
    clickTabfunction (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?

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签