【Vue3实战】将antd for Vue中Modal组件的确认框方法注册到vue全局方法
为了更方便使用的antd的modal组件中的确认框功能,需要注册到全局方法更方便,按如下操作即可
// 暴露confirm方法到globalProperties app.config.globalProperties.$confirm = async function (message: string, title: string, options?: any) { return new Promise((resolve, reject) => { let status: null | Number = null; Modal.confirm({ title: title, type: options?.type || 'info', content: message, onOk: () => { status = 1 }, onCancel: () => { status = 0 }, // // eslint-disable-next-line @typescript-eslint/no-empty-function // onCancel: callback2, }); let get= () =>{ setTimeout(() => { if (status !== null) { if (status == 1) { console.log('onOk'); resolve({}); } else { console.log('onCancel'); reject({}); } } else { get(); } }, 10) } get(); }); };
-- 展开阅读全文 --