Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

543
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda