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.

Recursive components problem: Vue.component() does not respect "name" prop defined in options

See original GitHub issue

JSFiddle: http://jsfiddle.net/fenivana/wso9prne/

Vue.js version: latest

tree.js:

module.exports = {
    name: 'v-tree',
  props: ['list'],
  template: '<ul>' +
              '<li v-for="item in list">{{item.value}}' + 
                '<v-tree v-if="item.children" :list="item.children"></v-tree>' + 
              '</li>' +
            '</ul>'
};

app.js:

var tree = require('./tree');

// registered the tree component with a different name
// e.g. add namespace
// this will cause error
Vue.component('ns-tree', tree);

// but if I registered it with
// Vue.component('ns-tree', Vue.extend(tree));
// this works fine.

new Vue({
    el: 'body',
    data: {
        list: [
        { value: 'foo' },
        { value: 'bar', children: [
          { value: 'baz' }
        ] }
      ]
    }
});

app.html:

<ns-tree :list="list"><</ns-tree>

Throws error:

VM408 vue.js:1018 [Vue warn]: Unknown custom element: <v-tree> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

Using Vue.component('ns-tree', Vue.extend(tree)) works fine, but this is verbose, and I need to tell the users of this component that you need to call Vue.extend() before Vue.component(), or you must register as the same name as the internal name.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

23reactions
appuristcommented, Aug 26, 2017

BTW, I found this issue because I was getting the did you register the component correctly? error as well. It seems the name member of a single-file .vue component is ignored. I’ve stopped including the names there, and started naming them in the components: member where they are referenced (or globally as above), e.g.:

import MyComponent from '@/components/MyComponent.vue';
export default {
  components: {
    'my-component': MyComponent
  }

That will only be valid there, but the other approach above can be used for global registrations.

It seems more appropriate to me to only register them where they are used (locally), however I’m not sure of the performance impact of registering them locally repeatedly, if it’s a component nested within many components.

13reactions
yyx990803commented, Jun 7, 2016

I think this is something that can be fixed since the expected behavior is reasonable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recursive component errors in Vue components
Which gave me: Failed to mount component: template or render function not defined. So in short, Contents.vue has Item.vue inside it, which has...
Read more >
Vue recursive components: Rendering nested comments
Explore how you can use recursive components in Vue to manage tree-like structured data with an example comments section.
Read more >
VueJS - Recursive Components - DEV Community ‍ ‍
Let's render this new component in Home.vue page. As the TreeNode represents only one node, we need to use a v-for directive to...
Read more >
Components - vue.js
Passing Data with Props. Every component instance has its own isolated scope. This means you cannot (and should not) directly reference parent data...
Read more >
Form Group | Components - BootstrapVue
When specifying the id, do not prepend it with # . The label-for prop should only be used when you have a single...
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