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要寫(xiě)在網(wǎng)絡(luò)請(qǐng)求成功的函數(shù)里面,否則不會(huì)出來(lái)數(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)輪播問(wèn)題。如果想設(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 nextTick延遲回調(diào)獲取更新后DOM機(jī)制詳解
這篇文章主要為大家介紹了Vue nextTick延遲回調(diào)獲取更新后DOM機(jī)制詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
vue中$set的使用(結(jié)合在實(shí)際應(yīng)用中遇到的坑)
這篇文章主要介紹了vue中$set的使用(結(jié)合在實(shí)際應(yīng)用中遇到的坑),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
vue+elementUl導(dǎo)入文件方式(判斷文件格式)
這篇文章主要介紹了vue+elementUl導(dǎo)入文件方式(判斷文件格式),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
vue.js 實(shí)現(xiàn)v-model與{{}}指令方法
這篇文章主要介紹了vue.js 實(shí)現(xiàn)v-model與{{}}指令方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10
vue2/vue3路由權(quán)限管理的方法實(shí)例
最近用vue框架做了個(gè)后臺(tái)管理項(xiàng)目,涉及權(quán)限,所以下面這篇文章主要給大家介紹了關(guān)于vue2/vue3路由權(quán)限管理的相關(guān)資料,需要的朋友可以參考下2021-06-06

