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 Components with resolveComponent(variableName) results in Vue warning and not rendering the component

See original GitHub issue

Environment

  • Operating System: Linux
  • Node Version: v16.15.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: npm@8.5.5
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://codesandbox.io/s/resolvecomponent-test-r98s25?file=/app.vue

Describe the bug

I try to create dynamic components. for reference I used this nuxt 3 documentation: https://v3.nuxtjs.org/guide/directory-structure/components#dynamic-components

The component name that is also the filename comes from a variable. When passing that variable into the resolveComponent function, the component doesn’t get rendered. Instead I get a vue warning:

[Vue warn]: Failed to resolve component: BaseBar If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

The expected behaviour would be that the component gets rendered correctly. When using the components name as a string directly inside the function, the component gets rendered. Only when using a variable it doesn’t.

Rendering the component should still work when passing a variable into that function. A typical use case would be that you get the components name that should get rendered from a cms / api.

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bjcoopercommented, Dec 20, 2022

@davidhellmann, thanks for sharing that! It works for me, trying to do something very similar where I resolve a Vue component dynamically based on a backend response. Awesome!

1reaction
danielroecommented, Aug 2, 2022

In that case you should register the dynamic components as global components: https://v3.nuxtjs.org/guide/directory-structure/components#dynamic-components.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't use dynamic components in Nuxt 3 - Stack Overflow
In Nuxt 2 it was no problem, but in Nuxt 3 (Vue 3 ?) it doesn't seem so easy. The variable dynComponent is...
Read more >
Dynamic Components with Vue's 'component' - Telerik
In this article we will explore Vue's , , and how to create dynamically loaded components.
Read more >
Vue.js - The Blue Book
Declarative Rendering: Vue extends standard HTML with a template syntax that allows us to declaratively describe HTML output based on JavaScript state.
Read more >
Dynamic & Async Components - Vue.js
To solve this problem, we can wrap our dynamic component with a ... Now the Posts tab maintains its state (the selected post)...
Read more >
Adding a new todo form: Vue events, methods, and models
Vue components are written as a combination of JavaScript objects that ... Finally for this section, render your ToDoForm component inside ...
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