大佬教程收集整理的这篇文章主要介绍了只需单击按钮即可打开模态,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
您试图仅在单击按钮后才渲染模态,这对于非反应性环境是很自然的,但在反应中它以不同的方式起作用。在最简单的解决方案中,@H_157_3@modal应始终呈现,当用户单击按钮时,将modalopen
属性更改为true
。
{ /* all the markup of your page */ }
<button onClick={() => this.setState({showModal: truE})}>Add Work Log</button>
{ /* anything else */ }
{ /* modal is here but it is hIDden */ }
<Modal open={this.state.showModal}>...</Modal>
或者,您可以完全跳过模式渲染,直到showModal
变为true。
this.state.showModal && <Modal open>...</Modal>
接下来的代码使用Modal react组件:
export class AddWorkLogEditor extends React.Component {
constructor(props) {
super(props);
this.addWorkLog = this.addWorkLog.bind(this);
this.onOpenModal = this.onOpenModal.bind(this);
this.onCloseModal = this.onCloseModal.bind(this);
this.state = {
open:true
};
}
onOpenModal() {
this.setState({open: this.props.openModal});
}
onCloseModal() {
this.setState({open:falsE});
}
addWorkLog() {
}
render() {
const bstyle = {
BACkgroundColor: 'green',textAlign:"left",paddingLeft: '0px',color: 'white'
};
const {open} = this.state;
return (
<div>
<Modal open={open} onClose={this.onCloseModal} little>
<h3>hi gi</h3>
<Button bsStyle="success" bsSize="small" onClick ={(ev) => {Console.log(ev)} }> Save </Button>
</Modal>
</div>
);
}
}
我正在尝试使用以下方式调用它:
addWorkLog()
{
return <AddWorkLogEditor/>;
}
和
createAddWorkLogButton () {
return (
<button style={ { color: '#007a86'} } onClick={this.addWorkLog} >Add Work Log</button>
);
}
我的意思是,单击此按钮后,没有任何显示。还有另一种方法可以调用该模式吗?我从以下位置导入模式:
从“反应-响应-模态”导入模态
以上是大佬教程为你收集整理的只需单击按钮即可打开模态全部内容,希望文章能够帮你解决只需单击按钮即可打开模态所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。