question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic component with auto imported components (component is)

See original GitHub issue

Environment

Stackblitz

Reproduction

https://stackblitz.com/edit/nuxt3-windicss-rktywp?file=components/Dynamic.vue

Describe the bug

<component :is doesn’t import components if they are not registered inside the dynamic component itself. From my recollection, this didn’t occur in Nuxt2.

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Mar 24, 2022

You either need to set components.global to true, or you can specifically resolve components you need, e.g.:

<template>
  <component :is="computedComp" />
</template>

<script setup>
const computedComp = computed(() => thing ? resolveComponent('LazySomeComponent') : resolveComponent('SomeOtherComponent'))
</script>

See https://github.com/nuxt/framework/discussions/2883.

0reactions
danielroecommented, Apr 12, 2022

The point is that it has to be a string so we can know to import it at build time. If you want to handle it dynamically you will need to set that component directory as a global component (or indeed all of your components as globally registered).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crank up auto import for dynamic Nuxt.js components
It prepares an array of components with their component names (PascalCase and kebab-case) and their relative filepaths. In a second step all ....
Read more >
Vue 3 use dynamic component with dynamic imports
I import all the possible components that can be added into componentName . With 30 possible components, it will be a long list....
Read more >
Dynamic & Async Components - Vue.js
// A dynamic import returns a Promise. () => import('./my-async-component') ) ...
Read more >
Dynamic Components with Vue's 'component' - Telerik
In this article we will explore Vue's <component> , <keep-alive> and how to create dynamically loaded components.
Read more >
Dynamic Imports for Components - Improving your Core Web ...
We can now import it as a dynamic component by adding the following at the beginning of the file: const CodeSampleModal = dynamic(()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found