這篇文章主要為大家展示了“VueAwesomeSwiper在VUE中的使用以及遇到的問題有哪些”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“VueAwesomeSwiper在VUE中的使用以及遇到的問題有哪些”這篇文章吧。
成都創(chuàng)新互聯(lián)公司成都網(wǎng)站建設(shè)定制開發(fā),是成都網(wǎng)站營銷推廣公司,為水電改造提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計、前端HTML5制作、后臺程序開發(fā)等。成都網(wǎng)站設(shè)計熱線:18982081108Vue-Awesome-Swiper
輪播圖插件,可以同時支持Vue.js(1.X ~ 2.X),兼顧PC和移動端,隨著vue的廣泛使用,其中插件swiper也算是使用的比較頻繁的插件,現(xiàn)在分享一下使用方法以及開發(fā)中會遇到的一些問題。
我們先下載包,然后去main.js里面配置。
npm install vue-awesome-swiper --save
我們可以用import的方法
//import import Vue from 'vue' import VueAwesomeSwiper from 'vue-awesome-swiper'
也可以用require
var Vue = require('vue') var VueAwesomeSwiper = require('vue-awesome-swiper')
兩者都可以達(dá)到目的,然后再mian.js里面全局注冊
Vue.use(VueAwesomeSwiper)
在模板里使用
import { swiper, swiperSlide } from 'vue-awesome-swiper' export default { components: { swiper, swiperSlide } }
<template> <swiper :options="swiperOption" ref="mySwiper"> <!-- slides --> <swiper-slide v-for="slide in swiperSlides" v-bind: :key="slide.id"></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> </swiper> </template> <script> import { swiper, swiperSlide } from 'vue-awesome-swiper' export default { name: 'carrousel', components: { swiper, swiperSlide }, data () { return { swiperOption: { //以下配置不懂的,可以去swiper官網(wǎng)看api,鏈接http://www.swiper.com.cn/api/ notNextTick: true, // notNextTick是一個組件自有屬性,如果notNextTick設(shè)置為true,組件則不會通過NextTick來實例化swiper,也就意味著你可以在第一時間獲取到swiper對象,假如你需要剛加載遍使用獲取swiper對象來做什么事,那么這個屬性一定要是true autoplay: true, loop: true, direction: 'horizontal', grabCursor: true, setWrapperSize: true, autoHeight: true, pagination: { el: '.swiper-pagination' }, centeredSlides: true, paginationClickable: true, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }, keyboard: true, mousewheelControl: true, observeParents: true, // 如果自行設(shè)計了插件,那么插件的一些配置相關(guān)參數(shù),也應(yīng)該出現(xiàn)在這個對象中,如下debugger debugger: true }, swiperSlides: ['../../static/img/swiper1.jpg', '../../static/img/swiper2.jpg', '../../static/img/swiper3.jpg', '../../static/img/swiper4.jpg'] } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style> html, body, #app { height: 100%; width: 100%; } .swiper-container-autoheight, .swiper-container-autoheight .swiper-slide { height: 100vh; } .swiper-pagination-bullet { width: 15px; height: 15px; } .swiper-pagination-fraction, .swiper-pagination-custom, .swiper-container-horizontal > .swiper-pagination-bullets { bottom: 8%; } </style>
這樣就可以正常使用了,但是以下是一些開發(fā)中遇到的一些問題。
很多人在引入swiper的時候會出現(xiàn)小點swiper-pagination出不來或者一些配置屬性沒有生效。原因是現(xiàn)在最新的swiper版本已經(jīng)開始區(qū)分組件和普通版本了。
在低版本swiper中,我們可以這么寫(我相信大部分童鞋百度,論壇到的使用方法大多是這樣子的)
<script> // swiper options example: export default { name: 'carrousel', data() { return { swiperOption: 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: true, } } }, } </script>
注意?。。?!
這其中的autoplay和pagination和prevButton和nextButton等屬性,在低版本中是允許這么使用的,并且可以功能正常生效,但是再高版本swiper中這樣寫不會生效,并且vue不會報錯。
接下來我們看官網(wǎng)api,拿分頁器pagination舉個栗子:
在以前低版本的swiper是沒有這樣子的區(qū)分的!所以現(xiàn)在我們可以看看最新版本的swiper分頁器的具體文檔:
圖中標(biāo)記的部分很明顯已經(jīng)不同于低版本的swiper的使用方法。
以上是“VueAwesomeSwiper在VUE中的使用以及遇到的問題有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計公司行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站名稱:VueAwesomeSwiper在VUE中的使用以及遇到的問題有哪些-創(chuàng)新互聯(lián)
本文鏈接:http://www.muchs.cn/article16/epdgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、域名注冊、標(biāo)簽優(yōu)化、云服務(wù)器、ChatGPT、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容