首页 > 其他分享 >解决 vue 项目使用 swiper 遇到设置轮播图自动播放不生效问题

解决 vue 项目使用 swiper 遇到设置轮播图自动播放不生效问题

时间:2022-10-13 22:11:07浏览次数:55  
标签:pagination vue 轮播 swiper 自动播放 import Swiper

前言

项目使用到 swiper 插件实现轮播图的功能,引入插件放上数据后,设置自动播放,但是发现没起效果,手动拖动可以

解决方法

安装指定版本

可以安装以下版本的,设置自动播放没有问题正常滚动

 "swiper": "^6.2.0"

引入:

<template>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <!-- 组件的内容由父组件传入,并且为 dom 结构时 -->
      <slot></slot>
    </div>
    <!--分页器。如果放置在swiper外面,需要自定义样式。-->
    <div class="swiper-pagination"></div>
  </div>
</template>
  
<script>
import Swiper from "swiper/bundle";
import "swiper/swiper-bundle.min.css";
export default {
  data() {
    return {};
  },
  mounted() {
    new Swiper(".swiper-container", {
      autoplay: true,
      // 分页器
      pagination: {
        el: ".swiper-pagination",
      },
    });
  },
};
</script>

最新版本

如果直接运行以下命令就是安装最新版本的,我就是使用这个安装的最新版本,设置自动滚动后不生效

npm i swiper

解决方法:

引入部分需要这样子写,可以解决轮播图自动滚动:
import "swiper/swiper-bundle.min.css";
import Swiper, { Navigation, Pagination, Autoplay } from "swiper";
Swiper.use([Autoplay, Navigation, Pagination]);

 mounted() {
    var mySwiper = new Swiper(".mySwiper", {
      slidesPerView: 5, // 可视个数
      spaceBetween: 10, // 间隔
      autoplay: {
        delay: 1500,
        disableOnInteraction: false,
      },
      loop: true, // 循环模式选项
      // 如果需要分页器
      // pagination: {
      //   el: ".swiper-pagination",
      // },
      // 如果需要前进后退按钮
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      }
    });
  },

标签:pagination,vue,轮播,swiper,自动播放,import,Swiper
From: https://www.cnblogs.com/clownblogs/p/16787953.html

相关文章

  • vue3 父子组件通信
    1.props父组件传参不变,子组件接收: <p>{{props.abc}}</p> <p>{{props.msg}}</p> constprops=defineProps({msg:{type:String,required:......
  • 【Vue】新建Vue项目
    前提条件熟悉命令行已安装16.0或更高版本的Node.js(附上node的安装教程)步骤主要步骤如下:确定已安装node环境。使用命令新建vue项目安装依赖并启动服务器接下......
  • vue3插槽变化
    1.默认插槽还是跟以前一样 2.使用具名插槽时,子组件不变以前的父组件掉用的时候<templateslot="example"></template>现在为<templatev-slot:exam......
  • vue拖拽排序功能
    实现效果(可以拖拽排序)  实现步骤一:安装依赖npminstallvuedraggable--save二:在页面中引入importdraggablefrom"vuedraggable";components:{draggab......
  • 前端Vue2-Day49
    Vue.set方法和vm.$set方法:参数(实例对象的某一属性名,属性名,属性值)用于给实例化Vue对象的某一个属性对象动态添加子属性。不允许直接给实例化对象添加属性。即参数第一项不......
  • vue项目搭建(vue2+elementUI+less)
    装node.js然后控制台输入node-v有版本号就是成功了  如是是windows系统建议装个git,我这边习惯用命令行了按照vue和vue-clivue-cli是一个vue的脚手架   ......
  • Vue组件上使用v-model之单选框
    子组件内容:<template><div><inputtype="radio":id="valueName":value="valueName":checked="picked===valueName":picked......
  • vue 项目引入 jquery
    一、引入jquery1.方式一默认会安装最新版本jquerynpminstalljquery 2.方式二指定版本[email protected] 3.方式三在package.json文件中 ......
  • element 表格自动轮播、echarts部分属性
    首先给<el-table>标签加上ref=“table”consttable=this.$refs.table//拿到表格中承载数据的div元素constdivData=tab......
  • 富文本 vue-quill-editor 用法
    1.下载npminstallvue-quill-editor--save2.在main.js中引入----全局引入//引入富文本importquillEditorfrom'vue-quill-editor'//引入样式import'quill/d......