I manage to create directly self nested components using the name
property and all works perfectly.
<template>
<div>
<span>Hi, I'm component A!</span>
<component-a></component-a>
</div>
</template>
<script>
export default {
name: 'component-a',
components: {
'component-a': this
}
}
</script>
Now, I want to create indirectly self nested components. Something like this:
ComponentA.vue:
<template>
<div>
<span>Hi, I'm component A!</span>
<component-b v-if="hasItems" v-for="item in items" :item="item"></component-b>
</div>
</template>
<script>
import ComponentB from './ComponentB.vue'
export default {
name: 'component-a',
components: {
'component-b': ComponentB
},
props: ['items'],
computed: {
hasItems() {
return this.items.length > 0
}
}
}
</script>
ComponentB.vue:
<template>
<div>
<span>Hi, I'm component B!</span>
<component-a v-if="hasItems" :items="item.items"></component-a>
</div>
</template>
<script>
import ComponentA from './ComponentA.vue'
export default {
name: 'component-b',
components: {
'component-a': ComponentA
},
props: ['item'],
computed: {
hasItems() {
return this.item.items.length > 0
}
}
}
</script>
But that fails. I get the following error:
[Vue warn]: Failed to mount component: template or render function not defined. (found in component )
Has anyone came across something like this and was able to solve it? According to the documentation we have control recursive components with conditional rendering that what I am doing... I even tried to use the name
prop on the components but it did nothing (nor I think it should since the components are not directly self-nested).