簡體   English   中英

Bootstrap Grid無法與ReactJS(create-react-app)一起使用

[英]Bootstrap Grid not working with ReactJS (create-react-app)

我正在嘗試使用“ create-react-app”在React上鍛煉項目。 我在同一項目本身中使用Bootstrap。 除“ Bootstrap Grid”外,它似乎工作正常。 從快照中可以看到,該項目似乎采用了自定義的Bootstrap字體和自定義的Bootstrap按鈕設計,但是,該項目無法加載和拾取Bootstrap Grid布局。

項目截圖

我正在為此項目使用“ create-react-app”。 以下是我的文件..

package.json ..

{
  "name": "demo-react-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "loaders.css": "^0.1.2",
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-loaders": "^2.6.0",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "^1.0.14",
    "react-select": "^1.0.0-rc.10",
    "react-slick": "^0.15.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

index.html ..

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <!--
      manifest.json provides metadata used when your web app is added to the
      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run     build`.
    -->
    <title>Demo React App</title>
    <!-- jQuery for Bootstrap -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
  </head>
  <body>
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

index.js ..

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

app.js ..

import React, { Component } from 'react';
// import logo from './logo.svg';
import './App.css';

import getRoutes from './routes.js';

import Header from './components/Header/Header.js';
import Footer from './components/Footer/Footer.js';

class App extends Component {
  render() {
    let RouterComponent = (
      <div>
        {getRoutes()}
      </div>
    );

    return (
      // <div className="App">
      //   <header className="App-header">
      //     <img src={logo} className="App-logo" alt="logo" />
      //     <h1 className="App-title">Demo React App</h1>
      //   </header>
      //   <p className="App-intro">
      //     To get started, edit <code>src/App.js</code> and save to reload.
      //   </p>
      // </div>

      <div className="container-fluid">
        <Header />
        <div className="row">
          <div className="col-md-offset-1 col-md-10 col-sm-offset-1 col-sm-10 col-xs-offset-1 col-xs-10">
            <button className='btn btn-default'>Press Me</button>
            {RouterComponent}
          </div>
        </div>
        <Footer />
      </div>
    );
  }
}

export default App;

route.js ..

import React from 'react';

import MainPage from './views/MainPage/MainPage.js';
import RandomPage from './views/RandomPage/RandomPage.js';
import ContactUsPage from './views/ContactUsPage/ContactUsPage.js';

import { HashRouter,Route } from 'react-router-dom';

export default function getRoutes() {
    return (
        <HashRouter>
            <div>
                <Route exact path='/' component={MainPage}></Route>
                <Route exact path='/RandomPage' component={RandomPage}></Route>
                <Route exact path='/ContactUsPage' component={ContactUsPage}></Route>
            </div>
        </HashRouter>
    );
}

我知道可以使用“ React Bootstrap”來替代它,但是,我很想知道為什么Twitter Bootstrap本身不能很好地與該項目集成。 謝謝。

PS:此外,控制台上沒有錯誤或警告。

您正在使用Bootstrap v4( v4.0.0-beta.2 ),因此以下文檔適用。 具體來說,這些類在v4中不存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM