A feature-rich swiper (slider) component for Vue.js applications.
Based on the powerful Swiper.js library.
How to use it:
1. Import and register the vue-awesome-swiper component.
// Globally import Vue from 'vue' import VueAwesomeSwiper from 'vue-awesome-swiper' // style (Swiper v6+) import 'swiper/swiper-bundle.css' // style (Swiper v5-) import 'swiper/css/swiper.css' Vue.use(VueAwesomeSwiper)
// locally import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper' // style (Swiper v6+) import 'swiper/swiper-bundle.css' // style (Swiper v5-) import 'swiper/css/swiper.css' export default { components: { Swiper, SwiperSlide }, directives: { swiper: directive } }
2. Use the vue-awesome-swiper as a component.
<template> <swiper ref="mySwiper" :options="swiperOptions"> <swiper-slide>Slide 1</swiper-slide> <swiper-slide>Slide 2</swiper-slide> <swiper-slide>Slide 3</swiper-slide> <swiper-slide>Slide 4</swiper-slide> ... more slides here <div class="swiper-pagination" slot="pagination"></div> </swiper> </template>
export default { name: 'carrousel', data() { return { swiperOptions: { pagination: { el: '.swiper-pagination' }, // more Swiper options } } }, computed: { swiper() { return this.$refs.mySwiper.$swiper } }, mounted() { console.log('Current Swiper instance object', this.swiper) this.swiper.slideTo(3, 1000, false) } }
3. Use the vue-awesome-swiper as a directive.
<template> <div v-swiper:mySwiper="swiperOption"> <div class="swiper-wrapper"> <div class="swiper-slide" :key="banner" v-for="banner in banners"> <img :src="banner"> </div> </div> <div class="swiper-pagination"></div> </div> </template>
export default { data () { return { banners: [ '1.jpg', '2.jpg', '3.jpg', '4.jpg'], swiperOption: { pagination: { el: '.swiper-pagination' }, // Swiper options } } }, mounted() { console.log('Current Swiper instance object', this.mySwiper) this.mySwiper.slideTo(3, 1000, false) } }
Preview:
Changelog:
04/22/2020
- v4.1.1
Download Details:
Author: surmon-china
Live Demo: https://surmon-china.github.io/vue-awesome-swiper/
Download Link: https://github.com/surmon-china/vue-awesome-swiper/archive/master.zip
Official Website: https://github.com/surmon-china/vue-awesome-swiper
Install & Download:
npm install vue-awesome-swiper --save