swiper中自动播放autoplay
- 1. swiper中设置轮播图的自动播放?
- 2. swiper 中设置了自动轮播,可是切换到别的页面,自动播放失效?
- 3. swiper中重新改变图片后,轮播图滑动不了?
1. swiper中设置轮播图的自动播放?
mounted () {
let mySwiper = new Swiper('#post_swiper_'+this.elId, {
observer: true,
observeParents: true,
lazyLoading: true,
pagination: {
el: '.swiper-pagination'
},
autoplay:{
delay: 3000,
disableOnInteraction: false,
},
})
},
2. swiper 中设置了自动轮播,可是切换到别的页面,自动播放失效?
methods: {
swiperInit () {
this.mySwiper = new Swiper('#post_swiper_' + this.elId, {
observer: true,
observeParents: true,
lazyLoading: true,
pagination: {
el: '.swiper-pagination'
},
autoplay:{
delay: 3000,
disableOnInteraction: false,
},
})
},
},
activated () {
console.log('每次进来')
this.swiperInit()
},
3. swiper中重新改变图片后,轮播图滑动不了?
<template>
<div class="swiper-container discoverSwiperContainer" :id="'post_swiper_'+elId" v-if="show">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="(image,index) in images" :key="index">
<!-- <img :src="config.imageOrigin+image" alt :data-src="config.imageOrigin+image" class="swiper-lazy" /> -->
<img
alt
:src="image"
:data-src="image"
@click="canClick ? handleClick(image) : ''"
>
</div>
</div>
<div class="swiper-pagination"></div>
</div>
</template>
<script>
import DiscoverHelper from '../helper'
export default {
data() {
return {
mySwiper: null,
show: this.pictures
}
},
props: {
pictures: {
type: String,
required: true
},
elId: {
type: String,
required: true
},
canClick: {
type: Boolean,
required: false
},
allImg: {
type: Array,
required: false
}
},
computed: {
images() {
return this.pictures.split(',')
}
},
watch: {
pictures(newV) {
return newV
},
images (newV) {
this.$nextTick(() => {
this.swiperInit()
})
return newV
}
},
mounted () {
this.mySwiper = new Swiper('#post_swiper_' + this.elId, {
allowTouchMove: true,
passiveListeners: false,
loop: false,
lazyLoading: true,
observer: true,
initialSlide: 0,
observer: true,
observeParents: true,
pagination: {
el: '.swiper-pagination'
},
on: {
zoomChange: function(scale, imageEl, slideEl) {
console.log(scale, 'scale')
}
}
})
},
methods: {
swiperInit() {
this.mySwiper = new Swiper('#post_swiper_' + this.elId, {
passiveListeners: false,
loop: false,
lazyLoading: false,
observer: true,
initialSlide: 0,
observer: true,
observeParents: true,
pagination: {
el: '.swiper-pagination'
}
})
}
}
}
</script>
<style lang="less">
.discoverSwiperContainer {
.swiper-slide {
img {
max-height: 133vw;
}
}
}
</style>