Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy load (dynamic) component with useModal() #423

Open
azabroflovski opened this issue Jan 17, 2024 · 1 comment
Open

Lazy load (dynamic) component with useModal() #423

azabroflovski opened this issue Jan 17, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@azabroflovski
Copy link

azabroflovski commented Jan 17, 2024

Is your feature request related to a problem? Please describe.

import { useModal } from 'vue-final-modal'
import SomeComponent from 'components'

const { open, close } = useModal({
   component: SomeComponent,
   attrs: {...},
})

// even if someEvent is not called, someComponent is loaded on the page
function someEvent() {
   open() // open modal
}

Describe the solution you'd like

import { useModal } from 'vue-final-modal'

// no need to add it to the bundle
// import SomeComponent from 'components' 

const { open, close } = useModal({
   component: async () => { ... } // load component when it needed
   attrs: {...},
})

/* 
 and when someEvent is triggered that causes the modal to open, 
 before opening the modal, it first loads its component over the network.
*/
async function someEvent() {
   await open() // open modal (wait loading of dynamic component)
}

Describe alternatives you've considered

Additional context

Thanks.

@azabroflovski azabroflovski added the enhancement New feature or request label Jan 17, 2024
@kkuegler
Copy link

kkuegler commented Sep 1, 2024

You can use Vue's defineAsyncComponent to do this:

import { useModal } from 'vue-final-modal'
import { defineAsyncComponent } from 'vue';

const { open, close } = useModal({
  component: defineAsyncComponent(() => import('./some-component.vue')),
  attrs: {...},
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants