[英]Bootstrap accordion not working properly with react
是一个非常新的反应和引导程序。 我遇到了手风琴无法正常工作的问题。 它没有颜色,当我单击它时,它会迅速滑动然后消失。 我已经看过入门,但并没有帮助。 我想念什么。
这是我的代码,谢谢
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;
我会回答我的问题。 即使我在粘贴时提到了“ 入门” ,我仍然拥有bootstrap 4 CDN 。 但是通过npm
我安装了旧版的bootstrap3。这是一个冲突,尽管某些功能(如按钮)仍然可以使用。 正确的样式表是这个
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">
手风琴代码看起来不错。 您是否确定将浏览器全局变量添加到index.html。 我很确定手风琴依赖于他们的javascript文件。 但是我确实注意到两件事。
您的state =
必须在super();
之后放入构造函数中super();
它应该是this.state=
。
您不必像这样从React Bootstrap单个库文件导入每个组件。 你可以做
import { Accordion, Panel, Button, ButtonToolbar, Modal, FormGroup, ControlLabel, FormControl} from 'react-bootstrap';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.