[Vuejs]-Attribute name from array of objects as varible?

0๐Ÿ‘

You can destructure inside a for loop. So your v-for would look like this:

<div v-for="({email, phone, address},index) in fields" :key="index">
<span> {{ email }}</span>
<span> {{ phone }}</span>
<span> {{ address}}</span>
</div>

0๐Ÿ‘

Oh thanks for comments Ive understand, my fault

i need transform data to:

  fields: [
    { key: email, value: 'ignat@domain.com' },
    { key: phone, value: '+1223456789' },
    { key: address, value: 'Paris, some address..' }
  ]

And Show it:

<div v-for="(field,index) in fields" :key="index">
<span> {{field.key}}</span>
<span> {{ field.value}}</span>
</div>

Thanks For Help!

Leave a comment