搜了很多都说用两个变量控制,我也试了,没起作用,是跟开启了自动切换有关吗?
<!--轮播图-->
<view class="wrap">
<swiper autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="true"
bindchange="swiperChange" current="{{cur}}">
<block wx:for="{{imgUrls}}" wx:key="index">
<swiper-item>
<navigator url="{{item.url}}" hover-class="navigator-hover">
<view class="index_top">
<image src="{{item.image}}" class="slide-image" mode="aspectFill"/>
</view>
</navigator>
</swiper-item>
</block>
</swiper>
<view class="dots">
<block wx:for="{{ imgUrls}}" wx:key="index" wx:for-index="idx">
<view class="dot{{idx == currentSwiper ? ' active' : ''}}"></view>
</block>
</view>
</view>
data: {
imgUrls: [
{'url': '../../images/banner.jpg'},
{'url': '../../images/banner.jpg'},
{'url': '../../images/banner.jpg'},],
cur: 0,
currentSwiper: 0,
autoplay: true, //是否自动轮播
interval: 2000, //间隔时间
duration: 500, //滑动时间
},
swiperChange: function (e) { //切换轮播图
console.log(e, e.detail.current, this.data.currentSwiper, this.data.cur)
this.setData({
// currentSwiper: e.detail.current,
})
},
你这个自动切换就会触发的呀:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html