关于vue3+ts+swiper,点击跳转到指定页问题

话不多说,直接上代码
 

<swiper :loop="false" :autoplay="{delay:1500,disableOnInteraction:false}"   class="mySwiperTwo" :modules="modules"  

            @slideChange="onSlideChange"  @swiper="setControlledSwiper" :controller="{ control: controlledSwiper }">

            <swiper-slide class="one firstImg" v-for="(item, index) in swiperList" :key="index">

              <div class="leftShowdown">

                <div class="textContent">

                  <p>{{ item.title }}</p>

                  <span>{{ item.text }}</span>

                  <div class="footerPie">

                    <li v-for="(item,index1) in 4" :key="index1" @click="pieChange(index1)">

                      <span v-if="index1 == currentPage"></span>

                    </li>

                  </div>

                </div>

              </div>

              <img :src="item.img" alt="">

            </swiper-slide>

          </swiper>

我这里是嵌套了一个swiper,第二个才是需要点击跳转到指定页

import { Swiper, SwiperSlide } from 'swiper/vue'; // swiper所需组件

import { Pagination, Navigation,Mousewheel ,Autoplay,Controller } from 'swiper/modules';

const modules = [Pagination, Mousewheel,Autoplay,Navigation,Controller ];

const controlledSwiper = ref();

const setControlledSwiper = (swiper:any) => {

    controlledSwiper.value = swiper;

    console.log(controlledSwiper.value);

   

};

const pieChange = (index:number)=>{

  currentPage.value = index

  controlledSwiper.value?.slideTo(index, 500)

}

核心问题就是在使用sideTo的时候需要引入控制器Controller,才能使用swiper实例当中的方法。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值