vue学习第四天 vue-swiper的使用

写博客不是我的爱好,只是人脑毕竟空间只有那么大,有时候会忘了,好记性不如烂笔头,所以通过博客记录点点滴滴,以后可以翻出来看。

vue-awesome-swiper官网链接https://www.npmjs.com/package/vue-awesome-swiper

和上一篇随笔一样,我们先下载包,然后去main.js里面配置。

1
npm install vue-awesome-swiper --save

  我们可以用import的方法

1
2
3
// import
import  Vue from  'vue'
import  VueAwesomeSwiper from  'vue-awesome-swiper'

  也可以用require

1
2
var  Vue = require( 'vue' )
var  VueAwesomeSwiper = require( 'vue-awesome-swiper' )

  两者都可以达到目的,然后再mian.js里面全局注册

1
Vue.use(VueAwesomeSwiper)

  在模板里使用

1
2
3
4
5
6
7
8
import  { swiper, swiperSlide } from  'vue-awesome-swiper'
 
export  default  {
   components: {
     swiper,
     swiperSlide
   }
}

  

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
41
42
43
44
45
46
47
48
<template>
   <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>
     <swiper-slide>I 'm Slide 5</swiper-slide>
     <swiper-slide>I' m Slide 6</swiper-slide>
     <swiper-slide>I 'm Slide 7</swiper-slide>
     <!-- Optional controls -->
     <div class="swiper-pagination"  slot="pagination"></div>//
     <div class="swiper-button-prev" slot="button-prev"></div>
     <div class="swiper-button-next" slot="button-next"></div>
     <div class="swiper-scrollbar"   slot="scrollbar"></div>
   </swiper>
</template>
  
<script>
   // swiper options example:
   export default {
     name: ' carrousel ',
     data() {
       return {
         swiperOption: {//以下配置不懂的,可以去swiper官网看api,链接http://www.swiper.com.cn/api/
           // notNextTick是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,<br>        假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true
           notNextTick: true,
           // swiper configs 所有的配置同swiper官方api配置
           autoplay: 3000,
           direction : ' vertical ',
           grabCursor : true,
           setWrapperSize :true,
           autoHeight: true,
           pagination : ' .swiper-pagination ',
           paginationClickable :true,
           prevButton:' .swiper-button-prev ',//上一张
           nextButton:' .swiper-button-next ',//下一张
           scrollbar:' .swiper-scrollbar', //滚动条
           mousewheelControl :  true ,
           observeParents: true ,
           // 如果自行设计了插件,那么插件的一些配置相关参数,也应该出现在这个对象中,如下debugger
           debugger:  true ,
         }
       }
     },
 
   }
</script>

  这样就可以使用啦

 

 

<-----------------------补充时间2017/9/22 21:00------------------------>

 

平时没怎么用这个插件,今天看了下,发现有点小小的改动,可能导致之前的受到影响,npm包发布者的原话是

// starting with version 2.6.0, you need to manually introduce swiper's css这句话的意思是:从版本2.6.0开始,您需要手动引入swiper的css
import 'swiper/dist/css/swiper.css'

我写这篇随笔的时候,还是2.4.2版本,还没有更新到2.6.0版本,所以并没有什么样式上的问题,今天我更新了包试了一下之前写的,发现样式上出问题了。所以才去找的文档,在此补充,希望能帮到各位

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值