perf: resolve beforeClose repeat trigger (#9283)

This commit is contained in:
jsdawn 2021-08-19 19:12:09 +08:00 committed by GitHub
parent b41ed5a130
commit c934710906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { PropType, reactive, defineComponent } from 'vue'; import { ref, PropType, reactive, defineComponent } from 'vue';
// Utils // Utils
import { import {
@ -68,10 +68,17 @@ export default defineComponent({
cancel: false, cancel: false,
}); });
const popupRef = ref();
const updateShow = (value: boolean) => emit('update:show', value); const updateShow = (value: boolean) => emit('update:show', value);
const close = (action: DialogAction) => { const close = (action: DialogAction) => {
updateShow(false); if (popupRef.value) {
popupRef.value.triggerClose();
} else {
updateShow(false);
}
if (props.callback) { if (props.callback) {
props.callback(action); props.callback(action);
} }
@ -221,6 +228,7 @@ export default defineComponent({
const { width, title, theme, message, className } = props; const { width, title, theme, message, className } = props;
return ( return (
<Popup <Popup
ref={popupRef}
role="dialog" role="dialog"
class={[bem([theme]), className]} class={[bem([theme]), className]}
style={{ width: addUnit(width) }} style={{ width: addUnit(width) }}

View File

@ -229,7 +229,7 @@ export default defineComponent({
} }
); );
useExpose({ popupRef }); useExpose({ popupRef, triggerClose });
useLockScroll(popupRef, () => props.show && props.lockScroll); useLockScroll(popupRef, () => props.show && props.lockScroll);