处理多个弹出窗口(material ui)的方法可以通过以下步骤来实现:
以下是一个示例代码:
import React, { useState } from 'react';
import { Button, Dialog, DialogTitle, DialogContent, DialogActions } from '@material-ui/core';
const App = () => {
const [openDialog1, setOpenDialog1] = useState(false);
const [openDialog2, setOpenDialog2] = useState(false);
const handleOpenDialog1 = () => {
setOpenDialog1(true);
};
const handleCloseDialog1 = () => {
setOpenDialog1(false);
};
const handleOpenDialog2 = () => {
setOpenDialog2(true);
};
const handleCloseDialog2 = () => {
setOpenDialog2(false);
};
return (
<div>
<Button onClick={handleOpenDialog1}>打开弹出窗口1</Button>
<Button onClick={handleOpenDialog2}>打开弹出窗口2</Button>
<Dialog open={openDialog1} onClose={handleCloseDialog1}>
<DialogTitle>弹出窗口1</DialogTitle>
<DialogContent>
<p>这是弹出窗口1的内容。</p>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseDialog1}>关闭</Button>
</DialogActions>
</Dialog>
<Dialog open={openDialog2} onClose={handleCloseDialog2}>
<DialogTitle>弹出窗口2</DialogTitle>
<DialogContent>
<p>这是弹出窗口2的内容。</p>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseDialog2}>关闭</Button>
</DialogActions>
</Dialog>
</div>
);
};
export default App;
在上述示例中,我们使用useState钩子函数来定义了两个状态变量openDialog1
和openDialog2
,分别用于控制弹出窗口1和弹出窗口2的显示与隐藏。通过点击按钮触发handleOpenDialog1
和handleOpenDialog2
事件处理函数来打开对应的弹出窗口,点击对话框中的关闭按钮或其他操作来关闭弹出窗口。
领取专属 10元无门槛券
手把手带您无忧上云