Swiper在Vue2中的簡(jiǎn)單使用方法
以swiper3為例
一、全局引入
1. 下載swiper3
cnpm install swiper@3 vue-awesome-swiper@3 --save-dev
2. 在main.js中引入Vue-Awesome-Swiper
import VueAwesomeSwiper from 'vue-awesome-swiper' import 'swiper/dist/css/swiper.css' // 全局掛載 Vue.use(VueAwesomeSwiper)
3. 在swiper.vue中
<template>
<div>
<swiper :options="swiperOption" ref="mySwiper">
<swiper-slide>I'm Slide 1</swiper-slide>
<swiper-slide>I'm Slide 2</swiper-slide>
<swiper-slide>I'm Slide 3</swiper-slide>
<div class="swiper-pagination" slot="pagination"></div>
</swiper>
</div>
</template>
<script>
export default {
name: 'HomeSwiper',
data () {
return {
swiperOption: {
loop: true,
autoplay: {
delay: 3000,
stopOnLastSlide: false,
disableOnInteraction: false
},
pagination: {
el: '.swiper-pagination',
type: 'fraction',
clickable: true
},
}
}
}
}
</script>
<style lang="scss" scoped></style>注意分頁(yè)器的寫法
2.6.7版本
swiperOption: {
loop: true,//可選選項(xiàng),開啟循環(huán)
autoplay: 5000,//可選選項(xiàng),自動(dòng)滑動(dòng)
pagination: '.swiper-pagination',
paginationType: 'fraction',
paginationClickable: true
}3.1.3版本
swiperOption: {
loop: true,
autoplay: {
delay: 3000,
stopOnLastSlide: true, //當(dāng)切換到最后一個(gè)slide時(shí)停止自動(dòng)切換
disableOnInteraction: true //用戶操作swiper之后,是否禁止autoplay
},
pagination: {
el: '.swiper-pagination',
type: 'fraction',
clickable: true
}
}二、按需引入
1. 下載swiper3
cnpm install swiper@3 vue-awesome-swiper@3 --save-dev
2. 在swiper.vue中 引入樣式和組件
<template>
<div>
<swiper :options="swiperOption" ref="mySwiper">
<swiper-slide>I'm Slide 1</swiper-slide>
<swiper-slide>I'm Slide 2</swiper-slide>
<swiper-slide>I'm Slide 3</swiper-slide>
<div class="swiper-pagination" slot="pagination"></div>
</swiper>
</div>
</template>
<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
import "swiper/dist/css/swiper.css";
export default {
name: 'HomeSwiper',
components: {
swiper,
swiperSlide
},
data () {
return {
swiperOption: {
loop: true,
autoplay: {
delay: 3000,
stopOnLastSlide: false,
disableOnInteraction: false
},
pagination: {
el: '.swiper-pagination',
clickable: true
}
}
}
}
}
</script>
<style lang="scss" scoped></style>loop: true失效問題
數(shù)據(jù)是寫死的時(shí)候,能夠loop:true是有效的;
數(shù)據(jù)是動(dòng)態(tài)獲取的loop:true就會(huì)失效。
解決辦法:
加上v-if="list.length"有效解決
computed: {
isShowSwiper () {
return this.list.length
}
}總結(jié)
到此這篇關(guān)于Swiper在Vue2中的簡(jiǎn)單使用方法的文章就介紹到這了,更多相關(guān)Vue2使用Swiper內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue項(xiàng)目中一定會(huì)用到的性能優(yōu)化技巧
這篇文章主要為大家介紹了vue項(xiàng)目中一定會(huì)用到的性能優(yōu)化技巧實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
Vue Element前端應(yīng)用開發(fā)之功能點(diǎn)管理及權(quán)限控制
在一個(gè)業(yè)務(wù)管理系統(tǒng)中,如果我們需要實(shí)現(xiàn)權(quán)限控制功能,我們需要定義好對(duì)應(yīng)的權(quán)限功能點(diǎn),然后在界面中對(duì)界面元素的功能點(diǎn)進(jìn)行綁定,這樣就可以在后臺(tái)動(dòng)態(tài)分配權(quán)限進(jìn)行動(dòng)態(tài)控制了,權(quán)限功能點(diǎn)是針對(duì)角色進(jìn)行控制的,也就是簡(jiǎn)稱RBAC(Role Based Access Control)。2021-05-05
Vue項(xiàng)目如何部署到Tomcat服務(wù)器上
這篇文章主要介紹了Vue項(xiàng)目如何部署到Tomcat服務(wù)器上,Vue中自帶webpack,可以通過(guò)一行命令將項(xiàng)目打包,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03
Vue中定義src在img標(biāo)簽使用時(shí)加載不出來(lái)的解決
這篇文章主要介紹了Vue中定義src在img標(biāo)簽使用時(shí)加載不出來(lái)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07

