tabs切换时,未保存提示

import { Modal, Tabs } from "antd";
import { useState } from "react";
import OneCom from "@/components/OneCom ";
import TwoCom from "@/components/TwoCom ";

const Demo: React.FC = () => {
    const [activeKey, setActiveKey] = useState('1');
    const [disable, setDisable] = useState(true);

    const items = [
        {
            label: 'tabs1',
            key: '1',
            children: ,
        },
        {
            label: 'tabs2',
            key: '2',
            children: ,
        }
    ]

    return (
        <>
             {
                    if (activeKey !== '2') {
                        setDisable(true);
                    }
                    if (key !== '2' && !disable) {
                        Modal.confirm({
                            content: '该页面有未保存的更改,确定要切换吗?',
                            okText: '确认',
                            cancelText: '取消',
                            onOk: async () => {
                                setActiveKey(key);
                                setDisable(true);
                                return true;
                            },
                        });
                    } else {
                        setActiveKey(key);
                    }
                }}
            />
        
    );
};
export default Demo;

你可能感兴趣的:(前端,javascript,开发语言)