我正在使用bootstrap类在react组件中调用Modal,其中Modal主体的右侧具有axios调用,我想在单击关闭按钮或“ X”按钮时清除Modal的右侧,因此那下一个弹出窗口右侧将再次为空,这可能吗?如果是,则不知道如何完成内置内置的引导程序类。
triggerHandler(){
axios.post(`http://localhost:8200/playit`)
.then( response=>{
console.log(response.data)
this.setState({
value:response.data
})
})
}
render(){
let value = this.state.value
return(
<div>
<div className="modal fade bd-example-modal-lg" id="exampleModal" tabIndex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div className="modal-dialog modal-lg" role="document">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="exampleModalLabel">Response and Trigger</h5>
<button type="button" className="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div className="modal-body">
<div className="row">
<div className="col-lg-6">
{
Hello
}
</div>
<div className="col-lg-6">
{value}
<button className="btn btn-primary" onClick={()=>this.triggerHandler()}>Trigger</button>
</div>
</div>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
);
}
如上所述,当我单击“ X”按钮上的关闭按钮时收到响应后,右侧应在关闭时变为空。
答案 0 :(得分:1)
onCloseModal = () => {
this.setState({value:""})
}
<button type="button" className="btn btn-secondary" data-dismiss="modal" onClick={()=>this.onCloseModal()}>Close</button>
在按钮上添加一个onCloseModal函数,将值设置为空字符串。