react中怎么使用基本swiper

  第一步:安装包

npm i swiper -S

  第二步:引包

import Swiper from 'swiper/dist/js/swiper.js'  
import 'swiper/dist/css/swiper.css'   

  第三步:写html

    <!-- Slider main container -->
    <div class="swiper-container">

        <!-- Additional required wrapper -->
        <div class="swiper-wrapper">

            <!-- Slides -->
            <div class="swiper-slide">Slide 1</div>
            <div class="swiper-slide">Slide 2</div>
            <div class="swiper-slide">Slide 3</div>
        </div>

        <!-- If we need pagination -->
        <div class="swiper-pagination"></div>

        <!-- If we need navigation buttons -->
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>

        <!-- If we need scrollbar -->
        <div class="swiper-scrollbar"></div>
    </div>

  第四步:调用  

  注意: // 直接引用数据将,new Swiper放在componentDidMount
      // 用axios请求数据,new Swiper放在componentDidUpdate

 

    new Swiper('.swiper-container', {
        direction: 'vertical',//竖向轮播
        loop: true,//无缝轮播
        pagination: {//小圆点分页
            el: '.swiper-pagination',
        },
        navigation: {//左右分页
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        scrollbar: {//下划线分页
            el: '.swiper-scrollbar',
        }
    })

 

参考网站:http://idangero.us/swiper/get-started/

 

posted on 2019-07-25 11:52  Ann&  阅读(8035)  评论(0编辑  收藏  举报