這篇文章主要介紹了react如何使用react-bootstrap,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
react入門之搭配環(huán)境(一)
可能很多人已經(jīng)打開過官方文檔學(xué)習(xí)了react的基礎(chǔ)知識(shí)
不管有沒有,在介紹react之前,我想先介紹一下react-bootstrap
先懂得使用別人造的輪子,就能更快成為老司機(jī)。
好的,源代碼奉上:
git clone https://github.com/lingjiawen/react_bootstrap_demo.git cd react_bootstrap_demo npm install npm run dev
打開瀏覽器輸入:localhost:8080
react-bootstrap官方網(wǎng)址
現(xiàn)在就讓我們來看看它能干什么吧!
一、Button
使用Button聲明一個(gè)按鈕,bsSize有如下四個(gè)屬性,可以分別有大、中、小、超小四種大小的按鈕,再用ButtonToolbar包裹起來
使用效果如下:
使用well將按鈕包裹起來,可以實(shí)現(xiàn)如下效果:(well在后面介紹)
使用 bsStyle屬性可以調(diào)整按鈕的狀態(tài)顏色:
下圖bsStyle屬性分別為:info、warning、danger、link
使用按鈕實(shí)現(xiàn)點(diǎn)擊loading,等待結(jié)果的功能:
點(diǎn)擊之后會(huì)變?yōu)閘oading...,可以自己點(diǎn)擊一下
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 ( ); } }
實(shí)現(xiàn)按鈕的下拉和上拉:
在title中使用Dropdown屬性,用DropdownButton包裹下拉,使用Dropup為上拉
//下拉//上拉
二、List
簡單列表:
Link 1 Link 2 Link 3
使用ListGroup包裹, ListGroupItem就是它的子元素
active:已選中
disable:可以取消它的點(diǎn)擊事件
表格:
# | First Name | Last Name | Username |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
可以點(diǎn)擊隱藏的面板:
class CollapsiblePanel extends React.Component { constructor(props) { super(props); this.state = { open: true }; } render() { return (); } }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.
三、Overlays
點(diǎn)擊彈出的窗口:
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 (); else return (Modal title One fine body... ); } }
以及點(diǎn)擊顯示、隱藏的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 (); } }Tooltip overload! Tooltip overload! Tooltip overload! Tooltip overload!
四、輪播
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.
五、一些有用的圖標(biāo)
class MiscellaneousInstance extends React.Component { constructor(props) { super(props); } render() { return (); } }Label
Label
Label
Label
Label
Label
六、表單
表單基礎(chǔ)的類函數(shù)為:
function FieldGroup({ id, label, help, props }) { return (); } {label} {help && {help} }
然后使用FieldGroup包裹:
便可以輕松實(shí)現(xiàn)表單!如果你對(duì)react有了解,便知道原生的表單是不能直接用的。這個(gè)組件簡化了許多,但我沒用實(shí)際用過,所以不知道效果如何。
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“react如何使用react-bootstrap”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián)成都網(wǎng)站制作公司,關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站制作公司行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、網(wǎng)站制作公司香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。