react中如何引入插件? - 网站

react中如何引入插件?

分类:React入门教程_React框架基础教程 · 发布时间:2020-05-22 14:06 · 阅读:1100

react中如何引入插件?下面本篇文章给大家通过实例介绍一下react中插件引用(react-slick、react-swipe、react-time)。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

1、react-slick{图片滑动展示、}

npm install react-slick

API参数说明:

PropertyTypeDescriptionWorking
accessibilitybool其他类名内滑动器的divYes
classNameString其他类名内滑动器的divYes
adaptiveHeightboolAdjust the slide's height automaticallyYes
arrowsbool是否要显示左右箭头吗?Yes
nextArrowReact ElementUse this element for the next arrow buttonYes
prevArrowReact ElementUse this element for the prev arrow buttonYes
autoplayboolShould the scroller auto scroll?Yes
autoplaySpeedintdelay between each auto scoll. in msYes
centerModeboolShould we centre to a single item?Yes
centerPadding
cssEase
customPagingfuncCustom paging templates. Yes
dotsboolShould we show the dots at the bottom of the galleryYes
dotsClassstringClass applied to the dots if they are enabledYes
draggableboolIs the gallery scrollable via dragging on desktop?Yes
easingstring
fadeboolSlides use fade for transitionYes
focusOnSelectbool点击响应幻灯片!Yes
infinitebool是否围绕幻灯片内容循环展开!Yes
initialSlideintwhich item should be the first to be displayedYes
lazyLoadboolLoads images or renders components on demandsYes
pauseOnHoverboolprevents autoplay while hoveringYes
responsivearray的形式的对象阵列{ breakpoint: int, settings: { ... } }的断点INTmaxWidth当分辨率低于该值,以便设定将被应用。阵列中的断点应该smalles责令最大。的设定对象来禁用那个断点渲染转盘使用到位“unslick”。例:[ { breakpoint: 768, settings: { slidesToShow: 3 } }, { breakpoint: 1024, settings: { slidesToShow: 5 } }, { breakpoint: 100000, settings: 'unslick' } ]Yes
rtlboolReverses the slide orderYes
slidestring
slidesToShowint一次可见多少个幻灯片数量Yes
slidesToScrollint每个导航项要滚动多少个幻灯片
speedint
swipebool
swipeToSlideboolAllow users to drag or swipe directly to a slide irrespective of slidesToScrollYes
touchMovebool
touchThresholdint
variableWidthbool
useCSSboolEnable/Disable CSS TransitionsYes
verticalboolVertical slide modeYes
afterChangefunctioncallback function called after the current index changesYes
beforeChangefunctioncallback function called before the current index changesYes
slickGoTointgo to the specified slide number

react-slick官网说明:http://www.bootcdn.cn/react-slick/readme/

slick插件说明:http://kenwheeler.github.io/slick/

2、react-swipe{图片滑动展示、}

npm install react swipe-js-iso react-swipe

第一种方式,全屏左右滑动效果

1.jpg-600

HTML代码为:

import React from 'react'
import ReactDOM from 'react-dom';
import ReactSwipe from 'react-swipe';

class Carousel extends React.Component {
constructor(props){
        super(props);
        this.state={
            datalist:[],
            playinglist:[]
        }
    }
    componentWillMount(){
        console.log(this.state.datalist.length)
        axios.get('v4/api/billboard/home').then(res=>{
            //接口错误排除
            if(res.data.data.billboards){
                this.setState({
                    datalist:res.data.data.billboards
                })
            }
        })
        axios.get('v4/api/film/now-playing').then(res=>{
            this.setState({
                playinglist:res.data.data.films
            })
        })
    }
    render() {
        return (
            <ReactSwipe className="carousel" swipeOptions={{continuous:true,auto:3000}} key={this.state.datalist.length}>
                 {
                     this.state.datalist.map((item)=>
                         <div key={item.id}>
                              <img src={item.imageUrl} style={{width:'100%'}} />
                         </div>
                     )
                 }
               </ReactSwipe>
        );
    }
}

ReactDOM.render(
    <Carousel />, 
    document.getElementById('app')
);

本地react-router4-app项目效果为: http://localhost:8095/home

react-swiper官网说明:http://www.bootcdn.cn/react-swipe/readme/

3、react-time{React组件用于格式化的日期到<time>HTML5元素}

npm install react-time

如果不行可能还依赖moment

npm install moment --save

2.jpg-600

HTML用法:

import React from 'react'
import Time from 'react-time'

class MyComponent extends React.Component {

  render() {
    let now = new Date()
    let wasDate = new Date("Thu Jul 18 2013 15:48:59 GMT+0400")
    return (
      <div>
        <p>Today is <Time value={now} format="YYYY/MM/DD" /></p>
        <p>This was <Time value={wasDate} titleFormat="YYYY/MM/DD HH:mm" relative /></p>
      </div>
    )
  }
}

另一种用法:

import React from 'react'
import Time from 'react-time'

class MyComponent extends React.Component {

  render() {
    return (
      <div>
        <div className="film-word2">
                               <span>上映日期:<Time value={this.state.info.premiereAt} format="YYYY年MM月DD日上映" /></span>
                               <span></span>
                          </div>
      </div>
    )
  }
}
<div className="col-xs-5 right">
     <div className="showing-date"><Time value={item.premiereAt} format="MM月DD日上映" /></div>
</div>

本地效果react-router4-app详情页查看:http://localhost:8095/detail/3071

react-time用法说明:https://www.ctolib.com/react-time.html#articleHeader0

更多web前端知识,请查阅 HTML中文网 !!

标签:
react 插件

相关文章

react中怎么使用sass?

方法:1、使用npm工具安装sass-loader和node-sass依赖;2、配置webpack.config.js文件;3、在需要的组件中引入scss,然后添加scss代码即可。

react怎么判断checkbox是否被选中

react判断checkbox是否被选中的方法:可以通过【if ($(&quot;#checkbox-id&quot;).get(0).checked) {}】方法来进行判断。还可以通过原生js方法来进行判断,如【ele.checked】。

react子组件如何向父组件传值?

在react中,首先通过父组件给子组件传递一个函数,然后子组件通过参数传到父组件,通过props来传递函数的引用,并通过回调的方式实现;其实就是子组件调用父组件的方法,把值以形参的方式传出来。

react组件什么时候会重新渲染?

每当组件状态改变时,React就会调用render函数进行重新渲染。更改状态意味着当调用setState函数时,React触发更新;这不仅意味着将调用组件的render函数,而且还意味着重新渲染其所有后续子组件,无论其prop是否已更改。

react组件生命周期有几个阶段?

React组件生命周期有三个阶段:加载、更新和卸载。加载阶段表示一个组件实例被创建并被插入到DOM中;更新阶段表示由状态或属性的改变导致组件的重新渲染;卸载阶段表示组件从DOM中移除。

返回分类 返回首页