();
const currentInstance = getCurrentInstance();
const [currentVisible, setVisible] = useDefault(
@@ -56,9 +56,8 @@ export default defineComponent({
// 因为开启 destroyOnClose,会影响 transition 的动画,因此需要前后设置 visible
watch(currentVisible, (v) => {
- wrapperVisible.value = v;
-
if (v) {
+ wrapperVisible.value = v;
if (props.destroyOnClose) {
nextTick(() => {
innerVisible.value = v;
@@ -132,37 +131,9 @@ export default defineComponent({
},
);
- const lock = () => {
- if (!lockTimes && isBrowser) {
- document.body.classList.add(bodyLockClass);
- }
-
- lockTimes++;
- };
-
- const unlock = () => {
- if (lockTimes) {
- lockTimes--;
+ useLockScroll(popupRef, () => wrapperVisible.value && props.preventScrollThrough, popupClass.value);
- if (!lockTimes && isBrowser) {
- document.body.classList.remove(bodyLockClass);
- }
- }
- };
-
- const shouldLock = computed(() => wrapperVisible.value && props.preventScrollThrough);
-
- watch(
- () => shouldLock.value,
- (value) => {
- value ? lock() : unlock();
- },
- );
- onUnmounted(() => {
- unlock();
- });
return {
- name,
to,
popupClass,
wrapperVisible,