Vue框架里使用Swiper的方法示例
下載swiper
首先使用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
})
},
注意
如果想要從后臺(tái)請(qǐng)求圖片放上去 new Swiper要寫在網(wǎng)絡(luò)請(qǐng)求成功的函數(shù)里面,否則不會(huì)出來數(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>
解釋一下:autoplay:true這樣可以解決不自動(dòng)輪播問題。如果想設(shè)置滾動(dòng)的時(shí)間,用speed設(shè)置相應(yīng)時(shí)間即可。direction可以設(shè)置輪播的方向。具體的參數(shù)可參考swiper的官網(wǎng)地址:http://www.swiper.com.cn/api/Effects/2015/0308/193.html
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
淺談Vue內(nèi)置component組件的應(yīng)用場(chǎng)景
這篇文章主要介紹了淺談Vue內(nèi)置component組件的應(yīng)用場(chǎng)景,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03
Vue項(xiàng)目打包問題詳解(生產(chǎn)環(huán)境樣式失效)
在Vue開發(fā)過程中,項(xiàng)目的打包是一個(gè)非常重要的步驟,下面這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目打包問題(生產(chǎn)環(huán)境樣式失效)的相關(guān)資料,文中介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12
Vue 引入AMap高德地圖的實(shí)現(xiàn)代碼
這篇文章主要介紹了Vue 引入AMap高德地圖的實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
前端Vue中常用rules校驗(yàn)規(guī)則(輪子)如電話身份證郵箱等校驗(yàn)方法例子
當(dāng)我們?cè)陂_發(fā)應(yīng)用時(shí)經(jīng)常需要對(duì)表單進(jìn)行校驗(yàn),以確保用戶輸入的數(shù)據(jù)符合預(yù)期,這篇文章主要給大家介紹了關(guān)于前端Vue中常用rules校驗(yàn)規(guī)則(輪子)如電話身份證郵箱等校驗(yàn)方法的相關(guān)資料,需要的朋友可以參考下2023-12-12
vue 實(shí)現(xiàn)左右拖拽元素并且不超過他的父元素的寬度
這篇文章主要介紹了vue 實(shí)現(xiàn)左右拖拽元素并且不超過他的父元素的寬度,需要的朋友可以參考下2018-11-11

