Recursive components problem: Vue.component() does not respect "name" prop defined in options
See original GitHub issueJSFiddle: 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:
- Created 7 years ago
- Reactions:2
- Comments:22 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 thecomponents:
member where they are referenced (or globally as above), e.g.: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.
I think this is something that can be fixed since the expected behavior is reasonable.