VueAwesomeSwiper在VUE中的使用以及遇到的一些问题

2020-06-16 06:08:33易采站长站整理

debugger: true
},
swiperSlides: ['../../static/img/swiper1.jpg', '../../static/img/swiper2.jpg', '../../static/img/swiper3.jpg', '../../static/img/swiper4.jpg'] }
}
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
html, body, #app {
height: 100%;
width: 100%;
}
.swiper-container-autoheight, .swiper-container-autoheight .swiper-slide {
height: 100vh;
}
.swiper-pagination-bullet {
width: 15px;
height: 15px;
}
.swiper-pagination-fraction, .swiper-pagination-custom, .swiper-container-horizontal > .swiper-pagination-bullets {
bottom: 8%;
}
</style>

这样就可以正常使用了,但是以下是一些开发中遇到的一些问题。

很多人在引入swiper的时候会出现小点swiper-pagination出不来或者一些配置属性没有生效。原因是现在最新的swiper版本已经开始区分组件和普通版本了。

在低版本swiper中,我们可以这么写(我相信大部分童鞋百度,论坛到的使用方法大多是这样子的)


<script>
// swiper options example:
export default {
name: 'carrousel',
data() {
return {
swiperOption:
notNextTick: true,
// swiper configs 所有的配置同swiper官方api配置
autoplay: 3000,
direction: 'vertical',
grabCursor: true,
setWrapperSize: true,
autoHeight: true,
pagination: '.swiper-pagination',
paginationClickable: true,
prevButton: '.swiper-button-prev',//上一张
nextButton: '.swiper-button-next',//下一张
scrollbar: '.swiper-scrollbar',//滚动条
mousewheelControl: true,
observeParents: true,
debugger: true,
}
}
},

}
</script>

注意!!!!

这其中的autoplay和pagination和prevButton和nextButton等属性,在低版本中是允许这么使用的,并且可以功能正常生效,但是再高版本swiper中这样写不会生效,并且vue不会报错。

接下来我们看官网api,拿分页器pagination举个栗子:

在以前低版本的swiper是没有这样子的区分的!所以现在我们可以看看最新版本的swiper分页器的具体文档:

图中标记的部分很明显已经不同于低版本的swiper的使用方法。