Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

542
Vistas
How can I change my imported chunk component to use defineAsyncComponent() in vue.js

Usually I import my component using chunk method like this in Vue.js to optimize my page performance especially regarding load speed, just for information I used Vue 2:

<template>
 <div>
  ... // some HTML code
  <ChildComponent />
 </div>
</template>

</script>
const ChildComponent = () => import(/* webpackPrefetch: true */ '../components/ChildComponent.vue');

export default {
    name: 'ParentComponent',
    components: { ChildComponent },
}
... //some script
</script>

<style lang="scss" scoped>
... // some styling
</style>

but today, my friend tell me that there is this method that Vue provide from version 2.3 for async function and it works the same as chunks as far as I read the docs in here, the name of this method is defineAsyncComponent, so I try to read it and it seems I can change my code easily into this:

</script>
const LoadPopup = () => import(/* webpackPrefetch: true */ '../components/LoadPopup.vue');
const ErrorPopup = () => import(/* webpackPrefetch: true */ '../components/ErrorPopup.vue');

const ChildComponent = defineAsyncComponent({
  // the loader function
  loader: () => import('../components/ChildComponent.vue'),

  loadingComponent: LoadPopup,
  delay: 200,
  errorComponent: ErrorPopup,
  timeout: 3000
})

export default {
    name: 'ParentComponent',
    components: { 
      ChildComponent: ChildComponent
    },
}
... //some script
</script>

And here is my question regarding this:

  1. what is the different between chunks method that I used in my former code than this method?
  2. Is my implementation already right regarding this?
  3. And last, is it correct if I want to add more component, then it means I can just make like const ChildComponent2 with the same way as my const ChildComponent and import it right under components above?
  4. and in this answer, why they only use error and loading instead of errorComponent and loadingComponent? is it a shorthand for it?

I hope someone can help me to get a better understanding regarding this problem, thankyou

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda