react使用antd的Modal.confirm时,怎么在外面获取点击哪个按钮。
import { Modal} from 'antd';
const cmdCan_Click = async () => {
await requestMsg(1);
};
//iAppMod=0或者iAppMod=1
const requestMsg = async (msgTyp: number) => {
switch (iAppMod) {
// 0
case baseConst.Add:
switch (msgTyp) {
case 0:
await msgDialog('是否确实要注册?');
break;
}
break;
// 1
case baseConst.Upd:
switch (msgTyp) {
case 0:
await msgDialog('可以更改吗');
break;
case 1:
await msgDialog('没有修改完成,确定要结束吗?');
break;
}
break;
};
const msgDialog = async (msg: string) => {
await Modal.confirm({
title: "test",
content: msg,
closable: true,
okText: "OK",
cancelText: "取消",
centered: true,
onOk() {
},
onCancel() {
},
})
};
在cmdCan_Click调用requestMsg()方法后,可以获取到msgDialog()对话框里面点击Ok还是Can按钮的值吗?在msgDialog里面renturn好像不行,requestMsg()方法不能得到返回值
利用 promise 封装一下就行了