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
915 stars 99 forks source link

Is it possible to access the dynamic modal instance created by $vfm.show after it is closed? #328

Closed johnson0903 closed 1 year ago

johnson0903 commented 1 year ago

Version

vue-final-modal: v3.4.11

In my use case, the content of dynamic modal is generated through AJAX. For example, a couple of form input.
I don't want to execute another AJAX call when I close it and then reopen it.

Currently I found that if I close the dynamic modal, I can't manipulate the closed modal through $vfm.modals or reopen it by calling $vfm.show(name, params)

hunterliu1003 commented 1 year ago

@johnson0903 ,

Yeah, it might be hard to manage the state of a dynamic modal in vue-final-modal@3.x without reopen a new modal. I recently released the vue-final-modal@4.x. VFM 4 provide a new way to manage dynamic modals and that is useModal() composable. It allow you to use patchOptions() to update the state of a dynamic modal that created by useModal(). For example:

const { open, close, patchOptions } = useModal({
  component: VueFinalModal,
  slots: {
    component: YourFormComponent,
    attrs: { ...SomePropsPassToYourFormComponent  }
  }
})

open() // open the dynamic modal

// You can use `patchOptions()` to update the specific state in a dynamic modal.
patchOptions({
  slots: {
    attrs: { ...ThePropsThatYouNeedToUpdate  }
  }
})

You can checkout the new documentation and see if you like the new way to manage dynamic modals in v4. If you decide to upgrade to v4, you can follow the migration guide.