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
})
},
注意
如果想要從后臺請求圖片放上去 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>
解釋一下:autoplay:true這樣可以解決不自動輪播問題。如果想設(shè)置滾動的時間,用speed設(shè)置相應時間即可。direction可以設(shè)置輪播的方向。具體的參數(shù)可參考swiper的官網(wǎng)地址:http://www.swiper.com.cn/api/Effects/2015/0308/193.html
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue nextTick延遲回調(diào)獲取更新后DOM機制詳解
這篇文章主要為大家介紹了Vue nextTick延遲回調(diào)獲取更新后DOM機制詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08
vue中$set的使用(結(jié)合在實際應用中遇到的坑)
這篇文章主要介紹了vue中$set的使用(結(jié)合在實際應用中遇到的坑),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07
vue.js 實現(xiàn)v-model與{{}}指令方法
這篇文章主要介紹了vue.js 實現(xiàn)v-model與{{}}指令方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-10-10

