vue-awesome-swiper(輪播圖vue插件)


Vue-Awesome-Swiper

輪播圖插件锄奢,可以同時(shí)支持Vue.js(1.X ~ 2.X)失晴,兼顧PC和移動(dòng)端,SPA和SSR拘央。

例子

例子:https://surmon-china.github.io/vue-awesome-swiper

安裝設(shè)置

安裝Install vue-awesome-swiper

npm install vue-awesome-swiper--save


vue掛載

//importimportVue from'vue'importVueAwesomeSwiper from'vue-awesome-swiper'//orrequirevarVue =require('vue')varVueAwesomeSwiper =require('vue-awesome-swiper')//mountwithglobalVue.use(VueAwesomeSwiper)//If usedinNuxt.js/SSR, you should keep it onlyinbrowser build environment//The `Process. BROWSER_BUILD` itselfisjust a feature, itisonly validinNuxt.js, you need to modify it according to your own procedures, suchas:invue official ssr scaffolding it should be` process.browser`if(process.BROWSER_BUILD) {constVueAwesomeSwiper =require('vue-awesome-swiper/ssr')? Vue.use(VueAwesomeSwiper)}//mountwithcomponent(can't work in Nuxt.js/SSR)

import { swiper, swiperSlide } from 'vue-awesome-swiper'

export default {

? components: {

? ? swiper,

? ? swiperSlide

? }

}


SPA與SSR中使用方法的區(qū)別

SPA通過組件作用涂屁,需要借助ref屬性查找swiper實(shí)例

SSR通過命令作用,需要借助命令參數(shù)查找swiper實(shí)例

其他配置和事件一致

SSR中的應(yīng)用

<!-- You can custom the "mySwiper" name used to find the swiper instance in current component -->exportdefault{? ? data () {return{? ? ? ? banners: ['/1.jpg','/2.jpg','/3.jpg'],? ? ? ? swiperOption: {? ? ? ? ? autoplay:5000,? ? ? ? ? initialSlide:1,? ? ? ? ? loop:true,? ? ? ? ? pagination:'.swiper-pagination',? ? ? ? ? onSlideChangeEnd: swiper => {? ? ? ? ? ? console.log('onSlideChangeEnd', swiper.realIndex)? ? ? ? ? }? ? ? ? }? ? ? }? ? },? ? mounted() {? ? ? console.log('app init')? ? ? setTimeout(() => {this.banners.push('/5.jpg')? ? ? ? console.log('banners update')? ? ? },3000)? ? ? console.log('This is current swiper instance object',this.mySwiper,'It will slideTo banners 3')this.mySwiper.slideTo(3)? ? }? }


SPA中的應(yīng)用

<!-- The ref attr used to find the swiper instance --><!-- slides -->I'm Slide 1I'm Slide 2I'm Slide 3I'm Slide 4I'm Slide 5I'm Slide 6I'm Slide 7<!-- Optional controls -->// swiper options example:exportdefault{? ? name:'carrousel',? ? data() {return{? ? ? ? swiperOption: {// NotNextTick is a component's own property, and if notNextTick is set to true, the component will not instantiate the swiper through NextTick, which means you can get the swiper object the first time (if you need to use the get swiper object to do what Things, then this property must be true)// notNextTick是一個(gè)組件自有屬性灰伟,如果notNextTick設(shè)置為true拆又,組件則不會(huì)通過NextTick來實(shí)例化swiper,也就意味著你可以在第一時(shí)間獲取到swiper對(duì)象袱箱,假如你需要?jiǎng)偧虞d遍使用獲取swiper對(duì)象來做什么事遏乔,那么這個(gè)屬性一定要是truenotNextTick: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,// if you need use plugins in the swiper, you can config in here like this// 如果自行設(shè)計(jì)了插件,那么插件的一些配置相關(guān)參數(shù)发笔,也應(yīng)該出現(xiàn)在這個(gè)對(duì)象中盟萨,如下debuggerdebugger:true,// swiper callbacks// swiper的各種回調(diào)函數(shù)也可以出現(xiàn)在這個(gè)對(duì)象中,和swiper官方一樣onTransitionStart(swiper){? ? ? ? ? ? console.log(swiper)? ? ? ? ? },// more Swiper configs and callbacks...// ...}? ? ? }? ? },// you can find current swiper instance object like this, while the notNextTick property value must be true// 如果你需要得到當(dāng)前的swiper對(duì)象來做一些事情了讨,你可以像下面這樣定義一個(gè)方法屬性來獲取當(dāng)前的swiper對(duì)象捻激,同時(shí)notNextTick必須為truecomputed: {? ? ? swiper() {returnthis.$refs.mySwiper.swiper? ? ? }? ? },? ? mounted() {// you can use current swiper instance object to do something(swiper methods)// 然后你就可以使用當(dāng)前上下文內(nèi)的swiper對(duì)象去做你想做的事了console.log('this is current swiper instance object',this.swiper)this.swiper.slideTo(3,1000,false)? ? }? }


異步數(shù)據(jù)例子

I'm Slide{{slide}}exportdefault{? ? name:'carrousel',? ? data() {return{? ? ? ? swiperOption: {? ? ? ? ? autoplay:3500,? ? ? ? ? setWrapperSize :true,? ? ? ? ? pagination :'.swiper-pagination',? ? ? ? ? paginationClickable :true,? ? ? ? ? mousewheelControl :true,? ? ? ? ? observeParents:true,? ? ? ? },? ? ? ? swiperSlides: [1,2,3,4,5]? ? ? }? ? },? ? mounted() {? ? ? setInterval(() => {? ? ? ? console.log('simulate async data')letswiperSlides =this.swiperSlidesif(swiperSlides.length


移動(dòng)端例子的代碼

例子:https://github.com/surmon-china/vue-awesome-swiper/blob/master/examples/41-mobile-fullpage-example.vue

SSR例子的代碼

例子:https://github.com/surmon-china/vue-awesome-swiper/blob/master/nuxt-ssr-example

API

參考官網(wǎng):?

http://www.swiper.com.cn/api/index.html

https://github.com/surmon-china/vue-awesome-swiper/blob/master/nuxt-ssr-example

我自己的前端學(xué)習(xí)交流群562862926,收集的一套前端教學(xué)視頻前计,全段學(xué)習(xí)路線分享給大家

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末胞谭,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子男杈,更是在濱河造成了極大的恐慌丈屹,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件返敬,死亡現(xiàn)場(chǎng)離奇詭異疫粥,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)槽惫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門先蒋,熙熙樓的掌柜王于貴愁眉苦臉地迎上來骇钦,“玉大人,你說我怎么就攤上這事竞漾∶写睿” “怎么了?”我有些...
    開封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵业岁,是天一觀的道長鳞仙。 經(jīng)常有香客問我,道長叨襟,這世上最難降的妖魔是什么繁扎? 我笑而不...
    開封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任幔荒,我火速辦了婚禮糊闽,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘爹梁。我一直安慰自己右犹,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開白布姚垃。 她就那樣靜靜地躺著念链,像睡著了一般。 火紅的嫁衣襯著肌膚如雪积糯。 梳的紋絲不亂的頭發(fā)上掂墓,一...
    開封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天,我揣著相機(jī)與錄音看成,去河邊找鬼君编。 笑死,一個(gè)胖子當(dāng)著我的面吹牛川慌,可吹牛的內(nèi)容都是我干的吃嘿。 我是一名探鬼主播,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼梦重,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼兑燥!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起琴拧,我...
    開封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤降瞳,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后蚓胸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體挣饥,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡斗塘,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了亮靴。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片馍盟。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖茧吊,靈堂內(nèi)的尸體忽然破棺而出贞岭,到底是詐尸還是另有隱情,我是刑警寧澤搓侄,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布瞄桨,位于F島的核電站,受9級(jí)特大地震影響讶踪,放射性物質(zhì)發(fā)生泄漏芯侥。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一乳讥、第九天 我趴在偏房一處隱蔽的房頂上張望柱查。 院中可真熱鬧,春花似錦云石、人聲如沸唉工。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽淋硝。三九已至,卻和暖如春宽菜,著一層夾襖步出監(jiān)牢的瞬間谣膳,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來泰國打工铅乡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留继谚,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓隆判,卻偏偏與公主長得像犬庇,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子侨嘀,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容