Swiper在Vue2中的簡單使用方法
以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>注意分頁器的寫法
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中的簡單使用方法的文章就介紹到這了,更多相關(guān)Vue2使用Swiper內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于vue實(shí)現(xiàn)8小時(shí)帶刻度的時(shí)間軸根據(jù)當(dāng)前時(shí)間實(shí)時(shí)定位功能
這篇文章主要介紹了基于vue實(shí)現(xiàn)8小時(shí)帶刻度的時(shí)間軸根據(jù)當(dāng)前時(shí)間實(shí)時(shí)定位功能,開始時(shí)間、結(jié)束時(shí)間可配置,根據(jù)當(dāng)前時(shí)間初始化位置,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05
vue-manage-system升級(jí)到vue3的開發(fā)總結(jié)分析
這篇文章主要為大家介紹了vue-manage-system升級(jí)到vue3的開發(fā)總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Vue中常用rules校驗(yàn)規(guī)則(實(shí)例代碼)
這篇文章主要介紹了Vue中常用rules校驗(yàn)規(guī)則,本文通過實(shí)例代碼個(gè)大家介紹了一些校驗(yàn)方法,需要的朋友可以參考下2019-11-11
手寫Vue源碼之?dāng)?shù)據(jù)劫持示例詳解
這篇文章主要給大家介紹了手寫Vue源碼之?dāng)?shù)據(jù)劫持的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
vue輸入框中輸完后光標(biāo)自動(dòng)跳到下一個(gè)輸入框中的實(shí)現(xiàn)方法
最近在工作中遇到了些問題,總結(jié)下分享給同樣遇到這個(gè)問題的朋友,這篇文章主要給大家介紹了關(guān)于vue輸入框中輸完后光標(biāo)自動(dòng)跳到下一個(gè)輸入框中的實(shí)現(xiàn)方法,需要的朋友可以參考下2023-03-03

