vue-awesome-swiper 问题

1.无法使用ref

		<Swiper loop ref="swiperRef" class="swiper animate__animated animate__fadeIn" :modules="modules"
				:slides-per-view="5" :centered-slides="true" :space-between="0" :grab-cursor="true"
				@swiper="onSwiperInit" @slide-change="changeSwiper" @click="clickSwiperItem">
				<SwiperSlide v-for="(n,index) in listTow" :key="index">
					<view class="swiper_list" v-show="list.length>0">
						<view :class="[currentImage === n.id ? 'image_box_1' : 'image_box']"></view>
						<image :class="currentImage===n.id&&'select_image'" class="swiper_slide_image"
							:src="n.iconPath0" />
					</view>
				</SwiperSlide>
			</Swiper>

//无法直接使用ref

	const swiperRef = ref(null)

//必须在初始化的时候赋值才能使用slideTo
	const onSwiperInit = (swiper) => {
		swiperRef.value = swiper

		setTimeout(() => {
			swiperRef.value.slideTo(swiperIndex.value, 500, false)
		}, 100)
	}

2.在开启loop后  点击SwiperSlide切换 后乱跳

//更改前	
	<Swiper loop ref="swiperRef" class="swiper animate__animated animate__fadeIn" :modules="modules"
				:slides-per-view="5" :centered-slides="true" :space-between="0" :grab-cursor="true"
				@swiper="onSwiperInit" @slide-change="changeSwiper" >
				<SwiperSlide v-for="(n,index) in listTow" :key="index" @click="clickSwiperItem">
					<view class="swiper_list" v-show="listTow.length>0">
						<view :class="[currentImage === n.id ? 'image_box_1' : 'image_box']"></view>
						<image :class="currentImage===n.id&&'select_image'" class="swiper_slide_image"
							:src="n.iconPath0" />
					</view>
				</SwiperSlide>
			</Swiper>

//更改后
	<Swiper loop ref="swiperRef" class="swiper animate__animated animate__fadeIn" :modules="modules"
				:slides-per-view="5" :centered-slides="true" :space-between="0" :grab-cursor="true"
				@swiper="onSwiperInit" @slide-change="changeSwiper" @click="clickSwiperItem">
				<SwiperSlide v-for="(n,index) in listTow" :key="index">
					<view class="swiper_list" v-show="listTow.length>0">
						<view :class="[currentImage === n.id ? 'image_box_1' : 'image_box']"></view>
						<image :class="currentImage===n.id&&'select_image'" class="swiper_slide_image"
							:src="n.iconPath0" />
					</view>
				</SwiperSlide>
			</Swiper>
//将click 给swiper  而不是SwiperSlide  获取其clickedIndex的值

	const clickSwiperItem = (e) => {
		swiperRef.value.slideTo(e.clickedIndex, 500, false);
	}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值