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/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>
    <!-- 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
    });
  }
Logo

前往低代码交流专区

更多推荐