Table of Contents
1.npm installation
2. Use
Home Web Front-end JS Tutorial How to use the vue-awesome-swiper carousel plug-in (code)

How to use the vue-awesome-swiper carousel plug-in (code)

Sep 15, 2018 pm 04:12 PM
javascript vue.js

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

1

npm i vue-awesome-swiper -S

Copy after login

I installed the following version here

How to use the vue-awesome-swiper carousel plug-in (code)

2. Use

  • to import globally:

1

2

3

4

5

import Vue from 'vue'

import vueSwiper from 'vue-awesome-swiper'

/* 样式的话,我这里有用到分页器,就在全局中引入了样式 */

import 'swiper/dist/css/swiper.css'

Vue.use(vueSwiper);

Copy after login
  • Component introduction

1

2

3

4

5

6

import { swiper, swiperSlide } from "vue-awesome-swiper";

require("swiper/dist/css/swiper.css");

components: {

  swiper,

  swiperSlide

},

Copy after login
  • Use in template

1

2

3

4

5

6

7

8

9

<swiper>

  <swiper-slide>

    <img  src="/static/imghw/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>

Copy after login

How to use the vue-awesome-swiper carousel plug-in (code)

How to use the vue-awesome-swiper carousel plug-in (code)

  • ##configuration in data

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

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"

        }

      }

   };

},

Copy after login
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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

/* 这里我是在使用接口请求后,对返回的数据进行判断 */

created() {

  this.$Request({

    url: '',

    method: 'get',

    success: res => {

      this.swiperOption.autoplay = res.result.data.length != 1 ? {

        delay: 1500,

        stopOnLastSlide: false,

        disableOnInteraction: false

        } : false;

     }

  })

}

Copy after login
  • 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

1

2

3

4

5

on: {

   slideChangeTransitionStart: function() {

      that.imgIndex = this.realIndex + 1;

   },

},

Copy after login
  • 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

The reason is because the data of this.commodity is [] at the beginning, and it has a value only after it is assigned, so you must first determine whether this.commodity If it is empty, the judgment will be made here in the swiper container. If the data length is 0, this container will not be displayed

1

<swiper></swiper>

Copy after login
Related recommendations:

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How to use insertBefore in javascript How to use insertBefore in javascript Nov 24, 2023 am 11:56 AM

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

See all articles