0
votes

i am getting some warning message.The data is displaying fine.How can i resolve the warning. Warning: vue.runtime TypeError: Cannot read property 'users' of undefined

   <tbody>
        <tr v-for= "(item,index) in data.profile.users" :key="index" >
          <template v-for="(date,user,i) in item">
            <td>
              {{user}}
            </td>
            <td>
              {{ date }}
            </td >
          </template>
        </tr>
      </tbody>

 export default {
   props:['data'],
 },
2
can you share your data.profile ? - omerS
Maybe <tr v-for= "(item,index) in data.profile && data.profile.users" :key="index" > - mare96

2 Answers

0
votes

It would be helpful if you could provide what the error message was. Just from looking at your code the issue could be:

The extra quote here

<td">
0
votes

Seems like your profile data isn't resolved yet. You can resolve it in a computed property and thane cast it values. Also notice that you can destructure your properties in v-for in order to access it, by default it takes value and index of iterable object.

   <tbody>
        <tr v-for= "({date, user}, i) in users" :key="i">
            <td>
              {{user}}
            </td>
            <td>
              {{ date }}
            </td>
        </tr>
      </tbody>

 export default {
   props:['data'],
   computed: {
     users() {
      return this.data?.profile?.users
     }
   }
 },