What is react swipe usage?

藏色散人
Release: 2021-11-26 11:21:46
Original
1977 people have browsed it

How to use react swipe: 1. Install swiper in the react project through "npm install swiper -s"; 2. Introduce "import React,{Component} from 'react'...".

What is react swipe usage?

The operating environment of this article: Windows7 system, react17.0.1, Dell G3.

What is the usage of swipe in react?

Using swiper in React

Although many ui frameworks have carousels Pictures are a revolving door, but sometimes our needs cannot be met by these.
Here I, a newbie, encountered a situation that required the picture and text list to be able to slide left and right. After searching for a long time, swiper was suitable for me.
Shown below Here’s my usage:

First, install swiper in the react project

npm install swiper -s
Copy after login

Then introduce it into the components that need to use swiper:

import React,{Component} from 'react'
import './new.css'
import Swiper from 'swiper/dist/js/swiper.js'
import 'swiper/dist/css/swiper.min.css'

class New extends Component{
    constructor(props){
        super(props);
        this.state={
            newlist:[0,1,2,3,4,5,6]
        }
    }
    componentDidMount() {
        new Swiper('.swiper-container', {
            slidesPerView: 3,
            centeredSlides: true,
            virtual: {
                slides:this.state.newlist,
            }
        })
    }
    render(){
        return(
            <p>
                </p><p>
                    </p><p>
                    </p>
                
                       
        )
    }
}

export default New;
Copy after login

The effect is like this:

What is react swipe usage?

You can slide left and right

Recommended learning: "react video tutorial"

The above is the detailed content of What is react swipe usage?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!