vue3 使用swiper7不能自动轮播

博客讲述了在Vue3项目中使用Swiper7时遇到的自动轮播不工作的问题。作者详细记录了从安装指定版本Swiper到尝试配置自动轮播的过程,并指出需要额外引入`Autoplay`模块才能实现自动轮播。最后提供了完整修复代码示例,并提醒开发者在使用Swiper时注意模块化需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

记录一次坑~

前言

swiper已经是到8了,但是目前还是在发展更新中,建议vue3的朋友们还是先用swiper7
安装的时候记得要加版本号npm install swiper@7.4.1
因为现在直接npm install swiper下载下来的是8.0.7的版本了
以下可以查看swiper的以往版本的对比数据,附上官网链接swiper各版本对比
在这里插入图片描述
想看各版本稳定版的也满足你们~
在这里插入图片描述

不能自动轮播

按照官网给的例子,然后加上 :autoplay="{ delay: 2500, disableOnInteraction: false }"

<template>
  <swiper :slides-per-view="1" :autoplay="{ delay: 2500, disableOnInteraction: false }" :loop="true" :space-between="50">
    <swiper-slide>Slide 1</swiper-slide>
    <swiper-slide>Slide 2</swiper-slide>
    <swiper-slide>Slide 3</swiper-slide>
    <swiper-slide>Slide 4</swiper-slide>
    <swiper-slide>Slide 5</swiper-slide>
    <swiper-slide>Slide 6</swiper-slide>
  </swiper>
</template>
<script lang="ts">
// Import Swiper Vue.js components
import { Swiper, SwiperSlide } from 'swiper/vue'

// Import Swiper styles
import 'swiper/css'
export default {
  components: {
    Swiper,
    SwiperSlide
  },
  setup() {
    return {
    }
  }
}
</script>

原以为能见到自动轮播,但是事实上毫无反应
还需要引入autoPlay这个模块!!!
swiper现在都模块化成这样了吗???
在这里插入图片描述
附上完整代码

<template>
  <swiper :slides-per-view="1" :autoplay="{ delay: 2500, disableOnInteraction: false }" :loop="true" :space-between="50" :modules="modules">
    <swiper-slide>Slide 1</swiper-slide>
    <swiper-slide>Slide 2</swiper-slide>
    <swiper-slide>Slide 3</swiper-slide>
    <swiper-slide>Slide 4</swiper-slide>
    <swiper-slide>Slide 5</swiper-slide>
    <swiper-slide>Slide 6</swiper-slide>
  </swiper>
</template>
<script lang="ts">
// Import Swiper Vue.js components
import { Swiper, SwiperSlide } from 'swiper/vue'
import { Autoplay } from 'swiper'

// Import Swiper styles
import 'swiper/css'
export default {
  components: {
    Swiper,
    SwiperSlide
  },
  setup() {
    return {
      modules: [Autoplay]
    }
  }
}
</script>

以后使用swiper7可得好好查看一下以下的模块了,分页、导航、滚动条、自动轮播、网格、淡入淡出等等
在这里插入图片描述
最后凡事还是得看官网swiper

完结啦!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小邓不爱吃芹菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值