1. import React from "react";
    2. import styled from "./index.module.css";
    3. interface Props {}
    4. interface State {
    5. isOpen: boolean;
    6. }
    7. class Modal extends React.Component<Props, State> {
    8. constructor(props: Props) {
    9. super(props);
    10. this.state = {
    11. isOpen: false,
    12. };
    13. }
    14. render() {
    15. return (
    16. <div className={styled.container}>
    17. <button
    18. className={styled.button}
    19. onClick={() => {
    20. this.setState({ isOpen: !this.state.isOpen });
    21. }}
    22. >
    23. 显示
    24. </button>
    25. <div
    26. className={styled.dropDown}
    27. style={{
    28. display: this.state.isOpen ? "block" : "none",
    29. }}
    30. >
    31. </div>
    32. </div>
    33. );
    34. }
    35. }
    36. export default Modal;