尔游网
您的当前位置:首页react ant design 通过函数弹出 modal窗口

react ant design 通过函数弹出 modal窗口

来源:尔游网

React Ant Design中,可以通过调用Modal组件的方法来动态弹出和关闭Modal窗口。具体步骤如下:

1、首先,在组件中引入Modal组件:

import { Modal } from 'antd';

2、在组件中定义一个函数来弹出Modal窗口:

const showModal = () => {
    Modal.info({
        title: 'This is a modal window',
        content: (
            <div>
                <p>Content of the modal</p>
            </div>
        ),
        onOk() {},
    });
};

3、在需要触发弹出Modal窗口的事件中调用showModal函数,比如一个按钮的点击事件:
<Button onClick={showModal}>Open Modal</Button>

通过以上步骤,当按钮被点击时,会弹出一个Modal窗口显示指定的内容。在Modal.info方法中,可以根据需求设置Modal的标题、内容和按钮点击事件等。

因篇幅问题不能全部显示,请点此查看更多更全内容