溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

react中swiper插件如何使用

發(fā)布時(shí)間:2020-11-26 09:56:23 來源:億速云 閱讀:1087 作者:栢白 欄目:web開發(fā)

這篇文章主要介紹了react中swiper插件如何使用,具有一定借鑒價(jià)值,需要的朋友可以參考下。下面就和我一起來看看吧。

方法:1、使用“npm i swiper -S”命令安裝swiper包;2、使用import語句引入swiper的css和js文件;3、在render中編寫swiper組件的結(jié)構(gòu),并在react的掛載生命周期函數(shù)內(nèi)創(chuàng)建Swiper對象即可。

react中swiper插件如何使用

  • 該方法適用于所有品牌的電腦。

react中使用基本swiper

第一步:安裝包

npm i swiper -S

第二步:引包

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

第三步:寫html

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

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

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

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

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

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

第四步:在react聲明周期里創(chuàng)建Swiper對象進(jìn)行調(diào)用

// 直接引用數(shù)據(jù)將,new Swiper放在componentDidMount
// 用axios請求數(shù)據(jù),new Swiper放在componentDidUpdate  

    new Swiper('.swiper-container', {
        direction: 'vertical',//豎向輪播
        loop: true,//無縫輪播
        pagination: {//小圓點(diǎn)分頁
            el: '.swiper-pagination',
        },
        navigation: {//左右分頁
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        scrollbar: {//下劃線分頁
            el: '.swiper-scrollbar',
        }
    })

以上就是react中swiper插件如何使用的詳細(xì)內(nèi)容了,看完之后是否有所收獲呢?如果想了解更多相關(guān)內(nèi)容,歡迎來億速云行業(yè)資訊!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI