1. 程式人生 > >vue2.0使用swiper元件實現輪播

vue2.0使用swiper元件實現輪播

1、安裝swiper

npm install [email protected].4.1 --save-dev

2、引用元件

import Swiper from 'swiper';
import 'swiper/dist/css/swiper.min.css';

3、html頁面程式碼

 <div class="swiper-container" id="swiper">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="(item,$index) in detail.imgs"
>
<a v-on:click="showPreview($index,detail.imgs,swiperObj)"> <figure class="wp-avatar banner"> <img v-cloak :src="item | toQiNiuImg"/> </figure> </a> </div> </div> <!-- Add Pagination -->
<div class="swiper-pagination"></div> </div>

4、初始化元件,並設定引數

 setTimeout(function () {
      state.swiperObj =  new Swiper('#swiper', {
        loop: true,
        pagination: '.swiper-pagination',
        autoplay: 2000,
        paginationClickable: true
      });
    }, 100
)

5、搞定,ok