uniapp中下拉刷新后轮播图swiper没有重置到第一页

项目场景:

今天练习的时候,发现给轮播图加下拉刷新的方法后,数据会重新打印,但是轮播图没有回到第一张图片


原因分析及解决:

刚开始以为是onPullDownRefresh方法的问题,查了很多资料,最后发现是swiper中要设置一下东西,看代码:
1、要设置current属性,意思是当前所在滑块的 index
2、要给swiper添加change事件 @change="changeswiper"
代码如下:

<swiper 
  	  @change="changeswiper" 
      :indicator-dots="true"
      indicator-color="rgba(255,255,255,.5)"
      indicator-active-color="#ff372b" 
      :autoplay="true" 
      :interval="3000" 
      :duration="500"
	  :current="currentswiper"
	  >
		<swiper-item v-for="(item,index) in swiper" :key="index">
			<view class="swiper-item">
				<image :src="item.imageUrl" mode="widthFix"></image>
			</view>
		</swiper-item>
</swiper>

<script>
export default{
data(){
return{
currentswiper:0
}
}
onPullDownRefresh() {
	// this.swiper = [];
	this.currentswiper = 0;//一定要在这里重置这个数据是0
	this.loadData()//轮播图接口重新请求,我这里写的是我代码中的请求方法,你们可以换成自己的
	//关闭下拉刷新
	setTimeout(() => {
	uni.stopPullDownRefresh();
	}, 1000);
},
methods:{
changeswiper(e) { // 一定得加上这个方法!!!否则无效
		this.currentswiper = e.detail.current
	},
}
}
</script>

以上,就可以实现下拉刷新后,轮播图返回第一页了~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值