Vue框架里使用Swiper
2018年05月23日 16:02:03 etemal_bright 阅读数:8168
下载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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
mounted里面调用
mounted(){
var mySwiper = new Swiper('.swiper-container', {
autoplay:true,
loop:true
})
},
- 1
- 2
- 3
- 4
- 5
- 6
注意
如果想要从后台请求图片放上去 new Swiper要写在网络请求成功的函数里面,否则不会出来数据。
本文详细介绍了如何在Vue项目中引入并使用Swiper轮播组件,包括使用npm或cnpm下载Swiper,导入Swiper及样式文件,以及在页面中设置Swiper容器和滑动项的方法。特别指出,在mounted生命周期钩子内初始化Swiper实例,并配置自动播放和循环播放选项。
253

被折叠的 条评论
为什么被折叠?



