vue3中swiper11的使用

news/2024/10/18 6:15:56/

Swiper官网
vue中使用方法

我使用的是 “vue”: “3.5.11”swiper版本为 swiper”: “11.1.14”“less”: “4.2.0”

1. swiperjs.com/swiper-api#parameters" rel="nofollow">属性介绍

属性名作用
slidesPerView设置slider容器能够同时显示的slides数量(carousel模式)。可以设置为数字(小数不可loop),或者 'auto’则自动根据slides的宽度来设定数量。
autoplayautoplay:{ delay: 2000 ,disableOnInteraction: false };❤️autoplay为自动切换函数;❤️ delay:轮播项的延迟时间;❤️ disableOnInteraction:用户操作之后时候禁止自动切换。
navigation使用前进后退按钮来控制Swiper切换。
paginationpagination=“{ type: ‘bullets’, clickable: true }” ;❤️pagination:使用分页器导航;❤️type:分页器样式;❤️clickable是否可点击跳转到对应图片。
paginationscrollbar=“{ draggable: true }” ❤️scrollbar:设置滚动条,❤️draggable:该参数设置为true时允许拖动滚动条
directionSwiper的滑动方向,可设置为水平方向切换 horizontal / 垂直方向切换 vertical
space-between在slide之间设置距离(单位px)
modules在项目中引入swiper 时,需要用到的 Swiper 模块

2. swiperjs.com/swiper-api#event-slideChange" rel="nofollow">方法介绍

事件作用
@swiper事件函数,返回swiper实例
@slideChange事件函数。在当前Slide切换到另一个Slide时执行(activeIndex发生改变),一般是在点击控制组件、释放滑动的时间点

3. 代码示例

<template><div class="swiper"><swiper:slidesPerView="1":autoplay="{ delay: 2000, disableOnInteraction: true }":navigation="true":pagination="{ type: 'bullets', clickable: true }":scrollbar="{ draggable: false }":space-between="0":modules="modules"@mouseenter="enter"@mouseleave="leave"@swiper="onSwiper"@slideChange="onSlideChange"><swiper-slide v-for="(item, index) in props?.swiperImgArray" :key="index" class="swiperItem"><img :src="item.img" alt="" /></swiper-slide></swiper></div>
</template>
<script setup lang="ts" name="AutoSwiper">import { toRaw } from "vue"import { Swiper, SwiperSlide } from "swiper/vue"import "swiper/css"import "swiper/less/navigation"import "swiper/less/pagination"import { Autoplay, Navigation, Pagination, Scrollbar, A11y } from "swiper/modules"interface Item {img: string}const props = defineProps<{ swiperImgArray: Item[] }>()let modules = [Autoplay, Navigation, Pagination, Scrollbar, A11y]//定义swiperNew,目的获取非响应式swiperlet swiperNew: any//鼠标移入const enter = () => {swiperNew.autoplay.stop()}//鼠标移出const leave = () => {swiperNew.autoplay.start()}const onSwiper = (swiper: any) => {// console.log(swiper);swiperNew = toRaw(swiper) //拿到swiper对象再转换为非响应式}const onSlideChange = () => {// console.log("slide change");}
</script>
<style lang="less" scoped>.swiper {width: 100%;height: 100%;img {width: 100%; height: 100%;}.swiperItem {// border: aqua solid 1px;// height: 200px;}}:deep(.swiper-pagination) .swiper-pagination-bullet.swiper-pagination-bullet-active {background-color: rgb(229, 127, 141);}:deep(.swiper-pagination-bullet) {//修改分页器圆点大小width: 8px;height: 8px;background-color: #fff;}.swiper-horizontal > .swiper-pagination-bullets .swiper-pagination-bullet,:deep(.swiper-pagination-horizontal.swiper-pagination-bullets) .swiper-pagination-bullet {// 分页器远点之间的距离margin: 0 10px;}:deep(.swiper-button-prev),:deep(.swiper-button-next) {color: rgb(229, 127, 141);}
</style>


http://www.ppmy.cn/news/1538840.html

相关文章

JavaWeb 19 AJAX

"我就是希望你好&#xff0c;就像很多人希望我好一样&#xff0c;特别简单&#xff0c;特别真挚。也不为了什么&#xff0c;就是希望你好" —— 24.10.13 一、什么是AJAX AJAX Asynchronous JavaScript and XML(异步的JavaScript和XML) AJAX不是新的编程语言&…

【华为HCIP实战课程十】OSPF网络DR和BDR实战讲解,网络工程师

一、DR与BDR的基础介绍 点到点同步LSA成本小 多点接入网络同步LSA成本大,需要DR/BDR 由于MA网络中,任意两台路由器都需要传递路由信息,网络中有n台路由器,则需要建立n*(n-1)/2个邻接关系。任何一台路由器的路由变化都会导致多次传递,浪费了带宽资源,DR和BDR应运而生!…

第二章 JVM规范

第二章 JVM规范 一. 章节概述1. 认识方式2. JVM概述JVM主要功能4. 虚拟机与平台关系 二. JVM规范1. 规范作用2. 规范主要内容3. Class字节码3.1 Class文件格式3.2 常量池3.3 类定义与属性 三. ASM---------------------------------------------------------------------------…

最新版IntelliJ IDEA 2024.2.3 创建SpringBoot项目(包含各种依赖的选择和功能)

创建SpringBoot项目 1 . 打开IDEA 选择新建项目 2. 基础项目创建 在顶端几个选项可以选择创建基本的java项目 填写项目名称,文件位置,选择构建工具 3. 下方选择springboot 选择构建的方式 三种方式虽然不同但是,基本功能都一致, Gradle-Groovy 是指使用 Groovy 语言编写…

第十六周:机器学习笔记

第十六周周报 摘要Abstratc一、机器学习1. Pointer Network&#xff08;指针网络&#xff09;2. 生成式对抗网络&#xff08;Generative Adversarial Networks | GAN&#xff09;——&#xff08;上&#xff09;2.1 Generator&#xff08;生成器&#xff09;2.2 Discriminator&…

Python网络爬虫技术详解

Python网络爬虫技术详解 引言 网络爬虫&#xff08;Web Crawler&#xff09;&#xff0c;又称网络蜘蛛&#xff08;Web Spider&#xff09;或网络机器人&#xff08;Web Robot&#xff09;&#xff0c;是一种按照一定规则自动抓取互联网信息的程序或脚本。它们通过遍历网页链…

SpringMVC源码-@ControllerAdvice和 @InitBinder注解源码讲解

1.ControllerAdvice修饰的类何时被加载扫描 被ControllerAdvice修饰的类是作用于全局的 initStrategies 初始化springmvc的9大组件 initStrategies:531, DispatcherServlet (org.springframework.web.servlet) onRefresh:514, DispatcherServlet (org.springframework.web.se…

《深度学习》OpenCV 物体跟踪 原理及案例解析

目录 一、物体跟踪 1、什么是物体跟踪 2、步骤 1&#xff09;选择跟踪算法 2&#xff09;初始化跟踪器 3&#xff09;在每个视频帧上执行跟踪 4&#xff09;可选的重新初始化 3、原理 二、案例实现 1、完整代码 1&#xff09;使用方式 2&#xff09;运行结果 2、关…