#Dynamic Imports

2 messages · Page 1 of 1 (latest)

sweet stratus
#

I am converting my company's Nuxt 2 app to Nuxt 3. Seems Dynamic Imports have changed. I am dynamically importing a component based on the route params during mounting phase of the component. looks something like this.

<script setup>
const { $route } = useNuxtApp()

const DynamicComponent = ref(null)

onMounted(() => {
  CreateAccountForm.value = () =>
    import(`~/components/${$route.params.id}/index.vue`)
})
</script>

<template>
  <div>
    <DynamicComponent />
  </div>
</template>

What is the new way in Nuxt 3 of Dynamically Importing components?

plain geode
#

Hey there @sweet stratus , in Nuxt 3 you can lazy load a component by simply adding the Lazy prefix to the component's name. Example: LazyFooter, LazyNavbar.