Complete the code to register a recursive component named 'TreeNode'.
<script>
export default {
name: '[1]',
props: { node: Object },
template: `<div>{{ node.name }}</div>`
}
</script>The component name must match the recursive component's name to allow self-reference.
Complete the template to recursively render child nodes inside 'TreeNode'.
<template>
<div>
<div>{{ node.name }}</div>
<ul>
<li v-for="child in node.children" :key="child.id">
<[1] :node="child" />
</li>
</ul>
</div>
</template>The component must call itself by its own name to render children recursively.
Fix the error in the component registration to enable recursion.
<script>
export default {
name: 'TreeNode',
props: { node: Object },
components: { [1] },
template: `<div>{{ node.name }}</div>`
}
</script>To use recursion, the component must register itself in 'components' with its own name.
Fill both blanks to complete a recursive component that renders nested lists.
<template>
<li>
{{ node.name }}
<ul v-if="node.children && node.children.length">
<[1] :node="child" v-for="child in node.children" :key="child.id" />
</ul>
</li>
</template>
<script>
export default {
name: 'TreeNode',
components: { [2] },
props: { node: Object }
}
</script>The component calls itself recursively in the template and registers itself in components.
Fill all three blanks to create a recursive component that displays a tree structure with proper props and registration.
<template>
<div>
<p>{{ [1].name }}</p>
<ul>
<li v-for="child in [2].children" :key="child.id">
<[3] :node="child" />
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'TreeNode',
components: { TreeNode },
props: { node: Object }
}
</script>The prop 'node' is used to access data, and the component calls itself by name 'TreeNode' recursively.