首頁 > web前端 > js教程 > 主體

React中使用BootStrap使用者體驗框架(詳細教學)

亚连
發布: 2018-06-01 10:03:38
原創
2917 人瀏覽過

這篇文章主要介紹了React BootStrap用戶體驗框架快速上手的相關知識,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

官方文檔http://react-bootstrap. github.io/getting-started.html

安裝

#在終端機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框架吧

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頁面上:




  es2105的写法
  
  <link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" >


登入後複製


效果如下:

React中使用BootStrap使用者體驗框架(詳細教學) 

主要看瀏覽器位址,這是我們前面設定的」熱啟動」。

執行指令 $ npm start 就開啟了服務

上面是我整理給大家的,希望今後會對大家有幫助。

相關文章:

使用vue中的v-for遍歷二維數組的方法

Vue-cli項目取得本機json檔案資料的實例

JavaScript中使用import 和require打包後實作原理分析

##

以上是React中使用BootStrap使用者體驗框架(詳細教學)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!