react如何使用react-bootstrap

这篇文章主要介绍了react如何使用react-bootstrap,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

玛曲ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

react入门之搭配环境(一)

可能很多人已经打开过官方文档学习了react的基础知识

不管有没有,在介绍react之前,我想先介绍一下react-bootstrap

先懂得使用别人造的轮子,就能更快成为老司机。

好的,源代码奉上:

git clone https://github.com/lingjiawen/react_bootstrap_demo.git
cd react_bootstrap_demo
npm install
npm run dev

打开浏览器输入:localhost:8080

 react-bootstrap官方网址

现在就让我们来看看它能干什么吧!

一、Button

使用Button声明一个按钮,bsSize有如下四个属性,可以分别有大、中、小、超小四种大小的按钮,再用ButtonToolbar包裹起来


          Large button
          Large button
        
        
          Default button
          
        
        
          Small button
          Small button
        
        
          Extra small button
          Extra small button
        

使用效果如下:

react如何使用react-bootstrap

使用well将按钮包裹起来,可以实现如下效果:(well在后面介绍)


   Block level button
   Block level button

使用 bsStyle属性可以调整按钮的状态颜色:

react如何使用react-bootstrap


Primary
Success

下图bsStyle属性分别为:info、warning、danger、link

react如何使用react-bootstrap

使用按钮实现点击loading,等待结果的功能:

react如何使用react-bootstrap

点击之后会变为loading...,可以自己点击一下

class LoadingButton extends React.Component{
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
    this.state = { isLoading: false }
  }

  handleClick() {
    this.setState({isLoading: true});

    // This probably where you would have an `ajax` call
    setTimeout(() => {
      // Completed of async action, set loading state back
      this.setState({isLoading: false});
    }, 2000);
  }

  render() {
    let isLoading = this.state.isLoading;
    return (
      
    );
  }
}

 实现按钮的下拉和上拉:

在title中使用Dropdown属性,用DropdownButton包裹下拉,使用Dropup为上拉

//下拉

  
  
  
     Dropdown link
     Dropdown link
  


//上拉

  
    Action
    Another action
    Something else here
    
    Separated link
  

react如何使用react-bootstrap

二、List

简单列表:


          Link 1
          Link 2
          Link 3
        

使用ListGroup包裹, ListGroupItem就是它的子元素

react如何使用react-bootstrap

表格: 

      
          
          
            #
            First Name
            Last Name
            Username
          
          
          
          
            1
            Mark
            Otto
            @mdo
          
          
            2
            Jacob
            Thornton
            @fat
          
          
            3
            Larry the Bird
            @twitter
          
          
        

react如何使用react-bootstrap

可以点击隐藏的面板: 

class CollapsiblePanel extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      open: true
    };
  }

  render() {
    return (
      
         this.setState({ open: !this.state.open })}>           点我隐藏/显示                             Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.           Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.                
    );   } }

react如何使用react-bootstrap

三、Overlays

点击弹出的窗口:

class StaticMarkup extends React.Component {
  constructor(props) {
    super(props);
    this.state = {dpName:false};
    this.onDisplayOverlays = this.onDisplayOverlays.bind(this);
    this.onCloseOverlays = this.onCloseOverlays.bind(this);
  }


  onDisplayOverlays() {
    this.setState({
      dpName:true
    });
  }

  onCloseOverlays() {
    this.setState({
      dpName:false
    });
  }

  render() {
    if(this.state.dpName)
      return (
        
                                                                  Modal title                                               One fine body...                                               Close                 Save changes                                       
        
      );     else       return (         
                   
      );   } }

react如何使用react-bootstrap

以及点击显示、隐藏的overload

class CustomOverlays extends React.Component{
  constructor(props) {
    super(props);
    this.state = {show: true};
    this.toggle = this.toggle.bind(this);
  }
  toggle() {
    this.setState({ show: !this.state.show });
  }

  render() {
    const sharedProps = {
      show: this.state.show,
      container: this,
      target: () => ReactDOM.findDOMNode(this.refs.target)
    };

    return (
      
        
          Click me!
        

        
          Tooltip overload!
        
        
          Tooltip overload!
        
        
          Tooltip overload!
        
        
          Tooltip overload!
        
      
    );   } }

react如何使用react-bootstrap 

四、轮播

class CarouselInstance extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      
        
          
          
            

First slide label

            

Nulla vitae elit libero, a pharetra augue mollis interdum.

          
        
                                           

Second slide label

            

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

          
        
                                           

Third slide label

            

Praesent commodo cursus magna, vel scelerisque nisl consectetur.

          
        
      
    );   } }

react如何使用react-bootstrap

五、一些有用的图标

class MiscellaneousInstance extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      
        
                                                                                                                                                   Star                               Star                Star                                 
        
          

Label 

          

Label 

          

Label 

          
Label 
          
Label 
          

Label 

        
      
    );   } }

react如何使用react-bootstrap

六、表单

表单基础的类函数为:

function FieldGroup({ id, label, help, props }) {
  return (
    
      {label}
      
      {help && {help}}
    
  );
}

然后使用FieldGroup包裹:

          

便可以轻松实现表单!如果你对react有了解,便知道原生的表单是不能直接用的。这个组件简化了许多,但我没用实际用过,所以不知道效果如何。

react如何使用react-bootstrap

感谢你能够认真阅读完这篇文章,希望小编分享的“react如何使用react-bootstrap”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!


网站标题:react如何使用react-bootstrap
本文网址:http://lszwz.com/article/ppsgss.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款