#lazy-component

2 messages · Page 1 of 1 (latest)

subtle tulipBOT
#

Hi @grim smelt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The "Lazy" prefix in Nuxt 3 is used for dynamically importing components, also known as lazy-loading. Here's a brief explanation of how it works and when to use it:

  1. Usage: To use a lazy component, simply add the "Lazy" prefix to the component's name in your template.

  2. Purpose: It delays loading the component's code until the right moment, which can help optimize your JavaScript bundle size.

  3. Implementation: Nuxt automatically creates a lazy-loaded version of your components.

Here's an example of how to use a lazy component:

<template>
  <div>
    <h1>Mountains</h1>
    <LazyMountainsList v-if="show" />
    <button v-if="!show" @click="show = true">Show List</button>
  </div>
</template>

<script setup lang="ts">
const show = ref(false)
</script>

In this example, the MountainsList component will only be loaded when the show variable becomes true.

It's important to note that while lazy components can improve performance, they shouldn't be overused. As mentioned in the Nuxt 3 Documentation, you should be careful not to overuse this feature.

For more detailed information about lazy components and dynamic imports in Nuxt 3, you can refer to the Nuxt 3 Components Documentation.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: