Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get field value of array

I have the followig:

<div class="label">{{ item.data[0] }}</div>

and in the view I’m having the following:

{
  "id": 6,
  "firtname": "JHON ",
  "lastname": "SCALA",
  "fullname": "JHON  SCALA"
}

I justo want to show fullname

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div class="label">{{ item.data[0].fullname }}</div>

but I’m having this error

TypeError: Cannot read properties of undefined (reading 'fullname')

why????

>Solution :

If the data is being fetched from database or any other async persistence, vue can’t read item.data[0].fullname before its loaded. Try wrapping the div in a v-if like this:

<template v-if="item.data.length > 0">
  <div class="label">{{ item.data[0].fullname }}</div>
</template>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading