Vue和React两个AntDesign可复用Modal Template

React Ant Design Modal

* useModal.js
export function useModal(callbackOk, callbackCancel) {
const [visible, setVisible] = useState(false)
const showModal = () => {
setVisible(true)
}
const handleOk = () => {
callbackOk().then(res => {
if(res) setVisible(false)
})
};
const handleCancel = () => {
callbackCancel()
setVisible(false);
};
return {
visible,
showModal,
handleOk,
handleCancel,
setVisible
}
}
* Modal.tsx
const {visible, showModal, handleOk, handleCancel} = useMdoal(callbackCustomOk, callbackCustomCancel)
// 当组件挂载后,将这个组件的实例传递给父组件
React.useImperativeHandle(ref, () => ({
showModal,
setDataSource
}));
<>
<Modal
destroyOnClose={true}
visible={visible}
title={''}
className={ModalStyl["keyMan-custom-modal"]}
bodyStyle={{height: '800px', overflowY: 'auto'}}
onCancel={handleCancel}
footer={[
<Button
key={"close"}
style={CLOSE_BTN_STYLE}
onClick={handleCancel}
>关闭</Button>,
<Button
key={"confirm"}
style={CONFIRM_BTN_STYLE}
onClick={handleOk}
>确认</Button>
]}
>
</Modal>
</>

Vue Ant Design Modal

<template>
<main>
<a-modal
title="我的订阅"
v-model:visible="open"
@ok="handleOk"
@cancel="handleCancel"
:destroyOnClose="true"
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</a-modal>
</main>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const open = ref<boolean>(false);
const showModal = () => {
open.value = true
}
const handleOk = (e: MouseEvent) => {
console.log(e)
open.value = false
}
const handleCancel = () => {
open.value = false
}
defineExpose({
showModal
})
</script>
posted @   Felix_Openmind  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
*{cursor: url(https://files-cdn.cnblogs.com/files/morango/fish-cursor.ico),auto;}
点击右上角即可分享
微信分享提示