Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
How to import component during the runtime

I started using Vue JS 3 and I would like to know if I can and its possible to import component ( modals ) during the runtime I tried that but didn't work

watch:{
        modal:{
            handler(newModal){
                App.component('modal', () => import(newModal))
            }
        }
    },
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can read about "Async Components" on the official Vue 3 documentation.

Basically, you can register a component as asynchronous, and it will lazyload itself when it tries to render the first time.

Simple defineAsyncComponent

<template>
  <div>
    <Modal v-if="open" />
  </div>
</template>

<script>
export default {
  components: {
    MySyncComponent,
    Modal: defineAsyncComponent(() => import('./Modal.vue'))
  }
}
</script>

Using <script setup>:

<script setup>
const Modal = defineAsyncComponent(() => import('./Modal.vue'))
</script>

Specifying custom lazyloading options:

const Modal = defineAsyncComponent({
  loader: () => import('./Modal.vue'),
  loadingComponent: ProgressSpinner,
  delay: 150, // waits 150ms before showing the loading spinner
  errorComponent: ErrorComponent,
  timeout: 2000 // if not loaded before 2s, will show error
})

Using <Suspense> wrapper component:

With the Suspense component, all child component will be treated as asynchronous by default. They will be in their own chunk of code.

<Suspense>
  <Modal v-if="open"> <!-- Loading as asynchronous -->
  <template #fallback>
    Loading...
  </template>
</Suspense>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!