提交 de12babd 作者: 无木

fix(modal): add v-model support for visible

上级 b387681c
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
components: { Modal, ModalWrapper, ModalClose, ModalFooter, ModalHeader }, components: { Modal, ModalWrapper, ModalClose, ModalFooter, ModalHeader },
inheritAttrs: false, inheritAttrs: false,
props: basicProps, props: basicProps,
emits: ['visible-change', 'height-change', 'cancel', 'ok', 'register'], emits: ['visible-change', 'height-change', 'cancel', 'ok', 'register', 'update:visible'],
setup(props, { emit, attrs }) { setup(props, { emit, attrs }) {
const visibleRef = ref(false); const visibleRef = ref(false);
const propsRef = ref<Partial<ModalProps> | null>(null); const propsRef = ref<Partial<ModalProps> | null>(null);
...@@ -157,6 +157,7 @@ ...@@ -157,6 +157,7 @@
() => unref(visibleRef), () => unref(visibleRef),
(v) => { (v) => {
emit('visible-change', v); emit('visible-change', v);
emit('update:visible', v);
instance && modalMethods.emitVisible?.(v, instance.uid); instance && modalMethods.emitVisible?.(v, instance.uid);
nextTick(() => { nextTick(() => {
if (props.scrollTop && v && unref(modalWrapperRef)) { if (props.scrollTop && v && unref(modalWrapperRef)) {
...@@ -180,7 +181,7 @@ ...@@ -180,7 +181,7 @@
} }
visibleRef.value = false; visibleRef.value = false;
emit('cancel'); emit('cancel', e);
} }
/** /**
...@@ -193,8 +194,8 @@ ...@@ -193,8 +194,8 @@
visibleRef.value = !!props.visible; visibleRef.value = !!props.visible;
} }
function handleOk() { function handleOk(e: Event) {
emit('ok'); emit('ok', e);
} }
function handleHeightChange(height: string) { function handleHeightChange(height: string) {
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
]; ];
}); });
function handleCancel() { function handleCancel(e: Event) {
emit('cancel'); emit('cancel', e);
} }
function handleFullScreen(e: Event) { function handleFullScreen(e: Event) {
e?.stopPropagation(); e?.stopPropagation();
......
...@@ -26,12 +26,12 @@ ...@@ -26,12 +26,12 @@
props: basicProps, props: basicProps,
emits: ['ok', 'cancel'], emits: ['ok', 'cancel'],
setup(_, { emit }) { setup(_, { emit }) {
function handleOk() { function handleOk(e: Event) {
emit('ok'); emit('ok', e);
} }
function handleCancel() { function handleCancel(e: Event) {
emit('cancel'); emit('cancel', e);
} }
return { handleOk, handleCancel }; return { handleOk, handleCancel };
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论