這篇文章給大家介紹Swiper怎么在Vue中使用,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
首先使用npm 或者cnpm下載swiper
cnpm install swiper
引入swiper
import Swiper from ‘swiper'; import ‘swiper/dist/css/swiper.min.css';
使用swiper
<div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="../../static/images/ad1.jpg" alt=""> </div> <div class="swiper-slide"> <img src="../../static/images/ad2.jpg" alt=""> </div> <div class="swiper-slide"> <img src="../../static/images/ad3.jpg" alt=""> </div> </div> </div>
mounted里面調(diào)用
mounted(){ var mySwiper = new Swiper('.swiper-container', { autoplay:true, loop:true }) },
注意
如果想要從后臺請求圖片放上去 new Swiper要寫在網(wǎng)絡(luò)請求成功的函數(shù)里面,否則不會出來數(shù)據(jù)。
slider組件的內(nèi)容如下:
<template> <swiper :options="swiperOption" ref="mySwiper"> <!-- slides --> <swiper-slide v-for="(picitem,index) in items" :key="index"> <img :src="picitem.src" alt=""> </swiper-slide> </swiper> </template> <script type="text/ecmascript-6"> import {swiper, swiperSlider} from 'vue-awesome-swiper' export default { data() { return { swiperOption: { notNextTick: true, loop: true, autoplay: true, speed: 1000, direction: 'horizontal', grabCursor: true, setWrapperSize: true, autoHeight: true, pagination: '.swiper-pagination', paginationClickable: true, mousewheelControl: true, observeParents: true, debugger: true }, items: [ {src: 'http://localhost/static/images/1.jpg'}, {src: 'http://localhost/static/images/2.jpg'}, {src: 'http://localhost/static/images/3.jpg'}, {src: 'http://localhost/static/images/4.jpg'}, {src: 'http://localhost/static/images/5.jpg'} ], } }, components: { swiper, swiperSlider } } </script> <style lang="stylus" rel="sheetstylus"> </style>
關(guān)于Swiper怎么在Vue中使用就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
本文題目:Swiper怎么在Vue中使用-創(chuàng)新互聯(lián)
新聞來源:http://www.rwnh.cn/article38/cssopp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)頁設(shè)計公司、云服務(wù)器、外貿(mào)建站、網(wǎng)站設(shè)計、定制開發(fā)
聲明:本網(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)