官方地址:https://www.npmjs.com/package/vue-awesome-swiper
npm安装:npm install vue-awesome-swiper --save
使用:
1.引入注册main.js
1 import Vue from ‘vue‘ 2 import VueAwesomeSwiper from ‘vue-awesome-swiper‘ 3 //也可以用require 4 //var Vue = require(‘vue‘) 5 //var VueAwesomeSwiper = require(‘vue-awesome-swiper‘) 6 7 Vue.use(VueAwesomeSwiper)
2.组件中使用
1 <template> 2 <div class="swiper1"> 3 <swiper :options="swiperOption" ref="mySwiper"> 4 <!-- slides --> 5 <swiper-slide>I‘m Slide 1</swiper-slide> 6 <swiper-slide>I‘m Slide 2</swiper-slide> 7 <swiper-slide>I‘m Slide 3</swiper-slide> 8 <swiper-slide>I‘m Slide 4</swiper-slide> 9 <swiper-slide>I‘m Slide 5</swiper-slide> 10 <swiper-slide>I‘m Slide 6</swiper-slide> 11 <swiper-slide>I‘m Slide 7</swiper-slide> 12 <!-- Optional controls --> 13 <div class="swiper-pagination" slot="pagination"></div> 14 <div class="swiper-button-prev" slot="button-prev"></div> 15 <div class="swiper-button-next" slot="button-next"></div> 16 <div class="swiper-scrollbar" slot="scrollbar"></div> 17 </swiper> 18 </div> 19 </template> 20 21 <script> 22 require(‘../assets/swiper-3.4.2.min.css‘) 23 24 import { swiper, swiperSlide } from ‘vue-awesome-swiper‘ 25 26 export default { 27 name:"swiper1", 28 components: { 29 swiper, 30 swiperSlide 31 }, 32 data() { 33 return { 34 swiperOption: {//以下配置不懂的,可以去swiper官网看api,链接http://www.swiper.com.cn/api/ 35 // notNextTick是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,<br> 假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true 36 notNextTick: true, 37 // swiper configs 所有的配置同swiper官方api配置 38 autoplay: 1000, 39 // direction : ‘vertical‘, 40 grabCursor : true, 41 setWrapperSize :true, 42 autoHeight: true, 43 pagination : ‘.swiper-pagination‘, 44 paginationClickable :true, 45 prevButton:‘.swiper-button-prev‘,//上一张 46 nextButton:‘.swiper-button-next‘,//下一张 47 scrollbar:‘.swiper-scrollbar‘,//滚动条 48 mousewheelControl : true, 49 observeParents:true, 50 // 如果自行设计了插件,那么插件的一些配置相关参数,也应该出现在这个对象中,如下debugger 51 debugger: true, 52 } 53 } 54 }, 55 } 56 </script> 57 58 <style scoped> 59 60 </style>
原文:https://www.cnblogs.com/luoshang/p/14489891.html