我正在使用 react-modal 但我关闭模式的按钮没有触发 onClick={this.handleCloseModal} 使模式内的按钮完全没有响应。我已经尝试了几个小时不同的事情,但无法弄清楚为什么这不起作用。控制台中没有弹出错误,我无法控制台记录任何内容....请参阅下面的代码,我只是一直在用头撞墙而没有答案。我对做出反应还很陌生,但觉得这应该可以正常工作,因为没有错误。先感谢您!
class Project extends React.Component {
constructor () {
super();
this.state = {
showModal: false
};
this.handleOpenModal = this.handleOpenModal.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this);
}
handleOpenModal () {
this.setState({ showModal: true });
}
handleCloseModal () {
this.setState({ showModal: false });
}
componentWillMount() {
ReactModal.setAppElement('body');
}
render() {
const details = this.props.details;
return (
<li className="Project" onClick={this.handleOpenModal}>
<img className="Project-image" src={'projects/' + details.image} alt={details.name}/>
<div className="Project-overlay">
<p>{details.name}</p>
</div>
<div >
<ReactModal
isOpen={this.state.showModal}
contentLabel="This is my Mods"
shouldCloseOnOverlayClick={true}
onRequestClose={this.handleCloseModal}
>
<div className="modal-header">
<h3>{details.name}</h3>
</div>
<div className="modal-body">
</div>
<div className="modal-footer">
<button onClick={this.handleCloseModal}>Close Modal</button>
</div>
</ReactModal>
</div>
<div className="Project-tag">
<p>{details.tag}</p>
</div>
</li>
)
}
}