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>gt;
// 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版本,所以並沒有什么樣式上的問題,今天我更新了包試了一下之前寫的,發現樣式上出問題了。所以才去找的文檔,在此補充,希望能幫到各位


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM