1

In the Parent component I have:

<todo-item v-for="(todo, index) in todos" :key="todo.id" :todo="todo" :index="index">

</todo-item>  

which just iterates through todos array and gets each todo object and by using props passes each Object and its index to the child component. todo-item registered in Child component.
todos is an array of objects:

todos: [
        {
          'id': 1,
          'title': 'Object 1'
        },
        {
          'id': 2,
          'title': 'Object 2'
        }
      ]    

Child component:

<template>
    <div class="todo-item">
         <div class="todo-item-left">
            <div>{{ todo.title }}</div>
       </div>

    </div>
</template>>

<script>
export default {
    name: 'todo-item',
    props: {
        todo: {
            type: Object,
            required: true
        },
        index: {
            type: Number,
            required: true
        }
    }
}
</script>  

I don't know why it doesn't render each todo on the page, I have a blank page. Even though in Vue DevTools It shows that I have these objects.
Vue DevTools inspection
Did I miss something?

EDIT:
There is an error, sorry the error flag were off hence didn't saw it.
Error message:

[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

As you can see above I did register the component in Child component.
And yes I did import the child component in Parent component by doing:

//Parent component
import ToDoItem from './ToDoItem'  
export default {
  name: 'todo-list',
  components: {
    ToDoItem,
  },
4
  • 1
    is there any errors? Commented Mar 1, 2020 at 9:30
  • are you sure you imported & used the child component correctly? Commented Mar 1, 2020 at 10:09
  • @BoussadjraBrahim yes, please see the updated question Commented Mar 1, 2020 at 11:01
  • please share the parent component script Commented Mar 1, 2020 at 11:09

2 Answers 2

2

You have problem with cases so you should import that component in parent one as follows :

 import TodoItem from './TodoItem'

and register it like :

export default{
  ....
components:{
       TodoItem
    }
 ....
 }

for more details check this

Sign up to request clarification or add additional context in comments.

7 Comments

As you can see in my question post, I did import and registered in this way. But I just now saw ur answer and tried to change as you did from ToDoItem => TodoItem. And it starts working ! Why it would care how i write it ? so weird
Initially, I wrote: import ToDoItem from './ToDoItem' components: { ToDoItem, }
then i just did: import TodoItem from './ToDoItem' components: { TodoItem, }
and the last one work just changed from capital D to small d.
your component is named todo-item with cabab-case format which will be converted to camelCase format
|
0

a common mistake

dont forget import child component in parent component

import ChildComponent fromt './ChildComponent';
export default{
components:{
       ChildComponent 
    }
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.