vue

Vue框架里使用Swiper

2018-12-04  本文已影响6人  world_7735

下载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>

mounted里面调用

    mounted(){
        var mySwiper = new Swiper('.swiper-container', {
          autoplay:true,
          loop:true
        })
      },

注意

如果想要从后台请求图片放上去 new Swiper要写在网络请求成功的函数里面,否则不会出来数据。

上一篇下一篇

猜你喜欢

热点阅读