vue-cli webpack 引入swiper的操作方法
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 结构
<!-- Swiper --> <div class="home_banner"> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="./../../assets/img/[email protected]"> </div> <div class="swiper-slide"> <img src="./../../assets/img/[email protected]"> </div> <div class="swiper-slide"> <img src="./../../assets/img/[email protected]"> </div> </div> </div> </div> <!-- Swiper end -->
8:vue js
mounted() { var mySwiper = new Swiper('.home_banner .swiper-container', { direction: 'horizontal', loop: true }); // Swiper 推荐课程 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 }); }
相关推荐
hline 2020-07-29
不知道该写啥QAQ 2020-07-18
helloxiaoliang 2020-06-21
Macuroon 2020-09-11
xiaodaiwang 2020-06-11
不知道该写啥QAQ 2020-05-17
xiaofanguan 2020-05-11
HeliumLau 2020-05-03
tozeroblog 2020-02-21
webfullStack 2020-02-11
csm0 2020-01-12
yezitoo 2020-01-11
HeliumLau 2019-12-07
学知不足业精于勤 2019-11-30
心动 2019-11-17
王军强 2019-11-17
webfullStack 2019-11-17
Macuroon 2019-11-17