Let's say I have an App.vue
file with the following
<template>
<task-list>
<task>Task 1</task>
<task>Task 2</task>
</task-list>
</template>
<script>
import TaskList from './tasklist.vue'
export default {
//...
components: {
TaskList
}
//...
}
</script>
a TaskList.vue
<template>
<ul>
<slot></slot>
</ul>
</template>
<script>
import Task from './task.vue'
export default {
//...
name: 'task-list'
components: {
Task
}
//...
}
</script>
a Task.vue
<template>
<li><slot></slot></li>
</template>
<script>
export default {
name: 'task',
//...
}
</script>
and a main.js
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
How do I import the sub-component Task.vue
only once in TaskList.vue
without also having to import it again in App.vue
It seems that if I do it this way, I get an error back from VueJS complaining about unregistered components
[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> at src/App.vue
Is there a way to indicate that task
is a sub-component of task-list
without global registration or importing again in App.vue
?
Task
component inside theTaskList
component template. This would make more sense. Or is there a specific reason why you choose not to do that? – pueloli
is always a child oful
, I want to know if there's a way to say that this component is a sub-component of another so I can just importtasks
inApp.vue
instead oftasks
andtask
– xort