官方文檔http://react-bootstrap.github.io/getting-started.html
安裝
在終端cd到你的項目目錄下執行:$ npm install react-bootstrap
然后需要我們手動引用css
<!-- Latest compiled and minified CSS --><link rel="stylesheet" ><!-- Optional theme --><link rel="stylesheet" >
但是我們在學習的時候使用外部的URL,太慢了。因此我們索引把bootstrap安裝到本地。
$ npm install bootstrap
然后你會發現在你的node_modules目錄下多了bootstrap。
這樣頁面上就可以引用本地的css了
<link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" >
好,我們動手來使用一下React-BootStrap框架吧
http://react-bootstrap.github.io/components.html
我們這里演示使用它的導航條組件
在index.js里:
const React = require("react");const ReactDOM = require("react-dom");import {Navbar} from "react-bootstrap";const navbarInstance = ( <Navbar> <Navbar.Header> <Navbar.Brand> <a href="#" rel="external nofollow" >react-bootstrap</a> </Navbar.Brand> </Navbar.Header> </Navbar>);// 然后我們渲染到body里ReactDOM.render(navbarInstance,document.body);
html頁面上:
<!DOCTYPE html><html><head> <title>es2105的寫法</title> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" ></head><body><div id="abc"></div></body> <script src="webpack-dev-server.js"></script> <script src="index-webpack.js"></script></html>
效果如下:
主要看瀏覽器地址,這是我們前面配置的”熱啟動”。
執行命令 $ npm start
就開啟了服務
總結
以上所述是小編給大家介紹的React BootStrap用戶體驗框架快速上手,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答