1:下载需要 swiper 的js文件和css文件
http://www.swiper.com.cn/
2:下载好swiper相关的js和css,js放在static目录下,css放在assets目录下。
3:安装runtime:
npm install babel-runtime
4:修改.eslintrc.js文件如下: 最后一行添加
'globals': {
"Swiper": true
}
5: vue模板中引入 swiper.min.js
import Swiper from '@/../static/js/swiper.min.js';
6: vue模板中引入 swiper-3.4.2.min.css
@import url("../../assets/css/swiper-3.4.2.min.css");
7: html 结构
<div class="home_banner">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="./../../assets/img/sec_3_top_2@2x.jpg">
</div>
<div class="swiper-slide">
<img src="./../../assets/img/sec_3_top_2@2x.jpg">
</div>
<div class="swiper-slide">
<img src="./../../assets/img/sec_3_top_2@2x.jpg">
</div>
</div>
</div>
</div>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
8:vue js
mounted() {
var mySwiper = new Swiper('.home_banner .swiper-container', {
direction: 'horizontal',
loop: true
});
var swiper2 = new Swiper('.course_swiper_wrap .swiper-container', {
slidesPerView: 3,
paginationClickable: true,
nextButton: '.swiper-button-next-01',
prevButton: '.swiper-button-prev-01',
spaceBetween: 30,
freeMode: true,
loop: true
});
}