vue-final / vue-final-modal

🍕Vue Final Modal is a tiny, renderless, mobile-friendly, feature-rich modal component for Vue.js.
https://vue-final-modal.org
MIT License
864 stars 95 forks source link

'close' method does not work for case when page was reloaded which contains hash to open image/video #373

Closed VasylHulpak closed 7 months ago

VasylHulpak commented 1 year ago

In case when click next/previous to see image the url is changing hash - the method works properly. But after page reloading, using watchEffect to open modal, close method does not work at all.

Version

vue-final-modal: 4.4.2 vue: 3.3.4

OS

Windows

Steps to reproduce

const { open, close } = useModal({
    component: PopupCarousel,
    attrs: {
        items: [{ src: '/test/1.jpg', src: '/test/2.jpg', src: '/test/2.jpg'}],
        currentIndex: 1,
        onClose() {
            close()
        }
    }
})

watchEffect(() => {
    const h = route.hash.match(/^#(.)=/g) && route.hash.match(/^#(.)=/g)[0]
    if (['#p='].some(s => h?.includes(s))) {
        open()
    }
})

What is Expected?

Close method should close the model

What is actually happening?

It trigger method before close but modal is still visible

hunterliu1003 commented 7 months ago

@VasylHulpak Can you provide a reproduction of this issue?