UNPKG

cjd-parkball

Version:

> 中后台业务组件库,中后台就像公园,进入需要买门票(登录),所以以 Parkball(公园球) 命名,公园内必定捕获!作为一个组件库,提供使用方法文档,方便开发者的调用

74 lines (62 loc) 1.45 kB
--- category: 2 title: 异步关闭 title_en: Asynchronously close --- zh-CN 点击确定后异步关闭对话框,例如提交表单。 en-US Asynchronously close a modal dialog when a user clicked OK button, for example, you can use this pattern when you submit a form. ````jsx import { Modal, Button } from 'parkball'; class App extends React.Component { state = { ModalText: 'Content of the modal', visible: false, confirmLoading: false, } showModal = () => { this.setState({ visible: true, }); } handleOk = () => { this.setState({ ModalText: 'The modal will be closed after two seconds', confirmLoading: true, }); setTimeout(() => { this.setState({ visible: false, confirmLoading: false, }); }, 2000); } handleCancel = () => { console.log('Clicked cancel button'); this.setState({ visible: false, }); } render() { const { visible, confirmLoading, ModalText } = this.state; return ( <div> <Button type="primary" onClick={this.showModal}> Open Modal with async logic </Button> <Modal title="Title" visible={visible} onOk={this.handleOk} confirmLoading={confirmLoading} onCancel={this.handleCancel} > <p>{ModalText}</p> </Modal> </div> ); } } ReactDOM.render(<App />, mountNode); ````