react-bootstrap无法按预期工作

时间:2017-11-01 19:56:54

标签: reactjs react-bootstrap

我正在尝试使用react-bootstrap来设置网页样式。

的package.json

{
  "name": "chrome-ui",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-scripts": "1.0.16"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "react-bootstrap": "^0.31.5"
  }
}

App.js

import React from 'react';
import { Button } from 'react-bootstrap'

function CheckState(props){
    function handleClick(e){
        console.log(props.state)
    }
    return(
        <Button bsStyle="primary" onClick={handleClick}>Click for state</Button>
    )
}

然而,这是我在刷新时在网页上看到的内容:

enter image description here

看起来没有添加样式。我究竟做错了什么?

3 个答案:

答案 0 :(得分:2)

在项目中包含 bootstrap.css 文件,如下所示: react-bootstrap-getting-started

答案 1 :(得分:1)

添加导入“ bootstrap / dist / css / bootstrap.css”;在您的index.js中

答案 2 :(得分:0)

在您的react应用程序中,打开index.js文件并添加import 'bootstrap/dist/css/bootstrap.css';