【问题标题】:Is there any error in my code because of which My collapse component is not working?我的代码中是否有任何错误导致我的折叠组件不起作用?
【发布时间】:2020-05-05 17:52:26
【问题描述】:

我正在创建一个 reactjs 网络应用程序,我想在其中使用折叠功能。所以我安装了 reactstrap 依赖并从那里导入“Collapse”组件。但它在我的代码中不起作用。

import { Component } from "react";
import React from "react";
import { Collapse, Navbar } from "reactstrap";
class Main extends Component {
  constructor(props) {
  super(props);
  this.state = {
  open: false
  };
}
 show() {
 this.setState({
  open: !this.state.open
  });
 }
 render() {
    return (
  <>
    <button onClick={() => this.show()}>Show</button>
    <Collapse isOpen={this.state.open}>
      <Navbar>hello</Navbar>
    </Collapse>
  </>
 );
}
}
export default Main;

查看demo这里。

【问题讨论】:

    标签: javascript reactjs web reactstrap


    【解决方案1】:

    在您的 index.js 文件中添加 import 'bootstrap/dist/css/bootstrap.min.css';

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多