vue-awesome-swiper是基於swiper的一個輪播圖插件,使用很是方便。css
首先安裝下vue
npm install vue-awesome-swiper --save
而後在入口文件main.js引入下npm
import VueAwesomeSwiper from 'vue-awesome-swiper' import './static/css/swiper.min.css' Vue.use(VueAwesomeSwiper)
最後運用到組件中segmentfault
<template> <div class="scroll"> <swiper :options="swiperOption" ref="mySwiper"> <!-- slides --> <swiper-slide>I'm Slide 1</swiper-slide> <swiper-slide>I'm Slide 2</swiper-slide> <swiper-slide>I'm Slide 3</swiper-slide> <swiper-slide>I'm Slide 4</swiper-slide> <!-- Optional controls --> <div class="swiper-pagination " slot="pagination"></div> <div class="swiper-button-prev swiper-button-black" slot="button-prev"></div> <div class="swiper-button-next swiper-button-black" slot="button-next"></div> <!-- <div class="swiper-scrollbar" slot="scrollbar"></div> --> </swiper> </div> </template> <script> import { swiper, swiperSlide } from 'vue-awesome-swiper' export default { name: 'HelloWorld', components: { swiper, swiperSlide }, data () { return { swiperOption: { notNextTick: true, //循環 loop:true, //設定初始化時slide的索引 initialSlide:0, //自動播放 autoplay:true, // autoplay: { // delay: 3000, // stopOnLastSlide: false, // disableOnInteraction: true, // }, // 設置輪播 effect : 'flip', //滑動速度 speed:800, //滑動方向 direction : 'horizontal', //小手掌抓取滑動 // grabCursor : true, //滑動以後回調函數 on: { slideChangeTransitionEnd: function(){ // console.log(this.activeIndex);//切換結束時,告訴我如今是第幾個slide }, }, //左右點擊 navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, //分頁器設置 pagination: { el: '.swiper-pagination', clickable :true } }, swiperSlides: [1, 2, 3, 4] } }, computed: { swiper() { return this.$refs.mySwiper.swiper; } }, mounted () { //可使用swiper這個對象去使用swiper官網中的那些方法 console.log('this is current swiper instance object', this.swiper); // this.swiper.slideTo(0, 0, false); } } </script>
容易出現的問題ide
一、vue-awesome-swiper組件pagination小圓點沒有顯示函數
二、組件沒有自動播放oop
參考文檔:https://segmentfault.com/a/1190000013995395this