Bootstrap手风琴无法正常反应

时间:2017-10-25 18:05:23

标签: twitter-bootstrap reactjs ecmascript-6 react-bootstrap

非常新的反应和引导。我遇到了手风琴不能正常工作的问题。它没有颜色,当我点击它快速滑动然后消失。我看过getting started,但没有帮助。我错过了什么。

这是我的代码,提前谢谢

import React, { Component } from 'react';
import './App.css'
import Accordion from 'react-bootstrap/lib/Accordion'
import Panel from 'react-bootstrap/lib/Panel'
import Button from 'react-bootstrap/lib/Button'
import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar'
import Modal from 'react-bootstrap/lib/Modal'
import FormGroup from 'react-bootstrap/lib/FormGroup'
import ControlLabel from 'react-bootstrap/lib/ControlLabel'
import FormControl from 'react-bootstrap/lib/FormControl'

class App extends Component {

state = {
    recipes: [
    {recipeName: 'recipe1', Ingredients: ['cheese', 'cheese', 'cheese']},
    {recipeName: 'recipe2', Ingredients: ['cheese', 'cheese', 'cheese']},
    {recipeName: 'recipe3', Ingredients: ['cheese', 'cheese', 'cheese']}
    ]
}

  render() {
    const {recipes} = this.state;
    return (
      <div className="App container">
    <Accordion>
        {recipes.map((recipe, index)=>(
            <Panel header={recipe.recipeName} eventKey={index} key={index}>
                <ol>
                    {recipe.ingredients.map((item)=>(
                        <li key={item}>{item}</li>
                    ))}
                </ol>
            </Panel >
        ))}
    </Accordion>
      </div>
    );
  }
}
export default App;

2 个答案:

答案 0 :(得分:1)

我会回答我的问题。即使我在粘贴时提到getting started在剪贴板上,我仍然有bootstrap 4 CDN。然而,通过npm我安装了旧版本的bootstrap 3.这是一个冲突,虽然像按钮这样的功能仍然可以工作。正确的样式表就是这个

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">

答案 1 :(得分:0)

Accordion代码看起来很好。您确定要将browser globals添加到index.html吗?我很确定Accordion依赖于他们的javascript文件。然而,我注意到了两件事。

  1. 您的state =需要在super();之后位于构造函数中,并且应该是this.state=

  2. 您不必从React Bootstrap单个库文件中导入每个组件。你可以改为

    import { Accordion, Panel, Button, ButtonToolbar, Modal, FormGroup, ControlLabel, FormControl} from 'react-bootstrap';