• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

react中如何引入插件?

react 搞代码 4年前 (2021-12-28) 38次浏览 已收录 0个评论

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

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

npm install react-slick

API参数说明:

Property Type Description Working
accessibility bool 其他类名内滑动器的div Yes
className String 其他类名内滑动器的div Yes
adaptiveHeight bool Adjust the slide's height automatically Yes
arrows bool 是否要显示左右箭头吗? Yes
nextArrow React Element Use this element for the next arrow button Yes
prevArrow React Element Use this element for the prev arrow button Yes
autoplay bool Should the scroller auto scroll? Yes
autoplaySpeed int delay between each auto scoll. in ms Yes
centerMode bool Should we centre to a single item? Yes
centerPadding
cssEase
customPaging func Custom paging templates. Yes
dots bool Should we show the dots at the bottom of the gallery Yes
dotsClass string Class applied to the dots if they are enabled Yes
draggable bool Is the gallery scrollable via dragging on desktop? Yes
easing string
fade bool Slides use fade for transition Yes
focusOnSelect bool 点击响应幻灯片! Yes
infinite bool 是否围绕幻灯片内容循环展开! Yes
initialSlide int which item should be the first to be displayed Yes
lazyLoad bool Loads images or renders components on demands Yes
pauseOnHover bool prevents autoplay while hovering Yes
responsive array 的形式的对象阵列{ breakpoint: int, settings: { ... } }的断点INTmaxWidth当分辨率低于该值,以便设定将被应用。阵列中的断点应该smalles责令最大。的设定对象来禁用那个断点渲染转盘使用到位“unslick”。例:[ { breakpoint: 768, settings: { slidesToShow: 3 } }, { breakpoint: 1024, settings: { slidesToShow: 5 } }, { breakpoint: 100000, settings: 'unslick' } ] Yes
rtl bool Reverses the slide order Yes
slide string
slidesToShow int 一次可见多少个幻灯片数量 Yes
slidesToScroll int 每个导航项要滚动多少个幻灯片
speed int
swipe bool
swipeToSlide bool Allow users to drag or swipe directly to a slide irrespective of slidesToScroll Yes
touchMove bool
touchThreshold int
variableWidth bool
useCSS bool Enable/Disable CSS Transitions Yes
vertical bool Vertical slide mode Yes
afterChange function callback function called after the current index changes Yes
beforeChange function callback function called before the current index changes Yes
slickGoTo int go 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

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

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

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<p style="color:transparent">来源gao!%daima.com搞$代*!码网</p> {

  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

更多react的相关知识,请查阅 搞代码网 !!

以上就是react中如何引入插件?的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:react中如何引入插件?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址