The content of this article is about how to use the vue-awesome-swiper carousel plug-in (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Mobile terminal carousel plug-in, after using the carousel component in the iview graphical interface plug-in to achieve touch sliding, instead use the vue-awesome-swiper plug-in
1.npm installation
npm i vue-awesome-swiper -S
I installed the following version here
2. Use
to import globally:
import Vue from 'vue' import vueSwiper from 'vue-awesome-swiper' /* 样式的话,我这里有用到分页器,就在全局中引入了样式 */ import 'swiper/dist/css/swiper.css' Vue.use(vueSwiper);
Component introduction
import { swiper, swiperSlide } from "vue-awesome-swiper"; require("swiper/dist/css/swiper.css"); components: { swiper, swiperSlide },
Use in template
<swiper> <swiper-slide> <img src="/static/imghwm/default1.png" data-src="item.image" class="lazy" alt="How to use the vue-awesome-swiper carousel plug-in (code)" > </swiper-slide> <!-- 常见的小圆点 --> <p></p> </swiper> <!-- 显示数字 --> <p>{{imgIndex}}/{{detailimages.length}}</p>
- ##configuration in data
data() { const that = this; return { imgIndex: 1, swiperOption: { //是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true notNextTick: true, //循环 loop: true, //设定初始化时slide的索引 initialSlide: 0, //自动播放 autoplay: { delay: 1500, stopOnLastSlide: false, /* 触摸滑动后是否继续轮播 */ disableOnInteraction: false }, //滑动速度 speed: 800, //滑动方向 direction: "horizontal", //小手掌抓取滑动 grabCursor: true, on: { //滑动之后回调函数 slideChangeTransitionStart: function() { /* realIndex为滚动到当前的slide索引值 */ that.imgIndex= this.realIndex - 1; }, }, //分页器设置 pagination: { el: ".swiper-pagination", clickable: true, type: "bullets" } } }; },3. Problems encountered
- This plug-in will still automatically scroll when there is only one picture One thing that needs to be noted here is that if you directly set autoplay to true, after you touch the sliding picture, it will no longer automatically scroll
/* 这里我是在使用接口请求后,对返回的数据进行判断 */ created() { this.$Request({ url: '', method: 'get', success: res => { this.swiperOption.autoplay = res.result.data.length != 1 ? { delay: 1500, stopOnLastSlide: false, disableOnInteraction: false } : false; } }) }
- In on, listen for slideChangeTransitionStart method, at the beginning, I used activeIndex to set the corresponding index value. In this case, no problem was found when sliding to the next picture. Later, when I tried to slide to the previous picture, I found that there was a problem. This value It doesn’t correspond anymore. Use realIndex
on: { slideChangeTransitionStart: function() { that.imgIndex = this.realIndex + 1; }, },
- In the swiper container, it will stop automatically scrolling after scrolling to the last picture, and the bottom edge will appear. The problem that the small dots are not displayed after writing
Related recommendations:<swiper></swiper>
How to use swiper carousel in vue Plug-in to implement carousel chart (code analysis)
Questions about the vue-awesome-swiper plug-in
The above is the detailed content of How to use the vue-awesome-swiper carousel plug-in (code). For more information, please follow other related articles on the PHP Chinese website!

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
