官方文档
安装
在终端cd到你的项目目录下执行:$ npm install react-bootstrap
然后需要我们手动引用css
<!-- latest compiled and minified css --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css"> <!-- optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap-theme.min.css">
但是我们在学习的时候使用外部的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框架吧
我们这里演示使用它的导航条组件
在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用户体验框架快速上手,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
2016年信息安全工程师综合知识第11-15题解析【建群网培信息安全工程师】
网友评论