Swiper簡介
Swiper常用于移動(dòng)端網(wǎng)站的內(nèi)容觸摸滑動(dòng)。
Swiper是純javascript打造的滑動(dòng)特效插件,面向手機(jī)、平板電腦等移動(dòng)終端。
Swiper能實(shí)現(xiàn)觸屏焦點(diǎn)圖、觸屏Tab切換、觸屏多圖切換等常用效果。
Swiper開源、免費(fèi)、穩(wěn)定、使用簡單、功能強(qiáng)大,是架構(gòu)移動(dòng)終端網(wǎng)站的重要選擇!
解決vue中使用swiper插件,在引入swiper插件后,發(fā)現(xiàn)無法正常運(yùn)行問題
這次我們模擬從后臺(tái)取下數(shù)據(jù),然后數(shù)據(jù)綁定在swiper標(biāo)簽中。
<template> <p class="homePage"> <abc></abc> <p id="banner"> <p class="swiper-container"> <p class="swiper-wrapper"> <p class="swiper-slide" v-for="items in swiper" ><a href=""><img :src=" rel="external nofollow" items.activity.img"></a></p> </p> <p class="swiper-pagination"></p> </p> </p> </p> </template> <script> import Swiper from "../../static/js/swiper-3.4.0.min.js"; import header from 'components/header.vue'; export default { components : { abc : header }, data(){ return { swiper:"" } }, mounted(){ this.$http.get("http://www.vrserver.applinzi.com/aixianfeng/apihome.php").then(function(res){ this.swiper=res.data.data.slide; var mySwiper = new Swiper('.swiper-container', { autoplay: 2000,//可選選項(xiàng),自動(dòng)滑動(dòng) //分頁器 pagination : '.swiper-pagination', paginationClickable :true, observer: true }) }) } } </script> <style type="text/css"> @import "../../static/css/home.css"; @import "../../static/css/swiper-3.4.0.min.css"; </style>
重點(diǎn)就在mounted()的使用,需要把這些方法都放在 mounted()里使用, mounted()是 vue生命周期鉤子 ,你也可以理解為當(dāng)掛載實(shí)例到 DOM完了后,才會(huì)觸發(fā)的而方法。
下面看下swiper在vue中的用法
首先通過npm i vue-awesome-swiper --save
來在vue中下載插件
然后再main.js中引入
require('swiper/dist/css/swiper.css') import VueAwesomeSwiper from 'vue-awesome-swiper' Vue.use(VueAwesomeSwiper)
接著在需要用到的組件里結(jié)構(gòu)中插入代碼
<p class="banner"> <swiper :options="swiperOption"> <swiper-slide v-for="items in allData.bannerphoto" key="items"> <img :src="items" alt=""> </swiper-slide> <p class="swiper-pagination" slot="pagination"></p> </swiper> <p class="jc"></p> </p>
然后在data中定義輪播圖
swiperOption: { pagination: '.swiper-pagination', paginationClickable: true, autoplay: 2500, autoplayDisableOnInteraction: false, loop: false, coverflow: { rotate: 30, stretch: 10, depth: 60, modifier: 2, slideShadows : true } },
此時(shí)的coverflow是輪播圖切換的方式 更改屬性可切換輪播模式。
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注Gxl網(wǎng)其它相關(guān)文章!
推薦閱讀:
express默認(rèn)日志組件morgan的詳細(xì)介紹
webpack的熱模塊替換HMR/熱更新的具體步奏
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com