[Vuejs]-How to display only one element of an array in Vue.js?

4👍

If you want to display only one element of the multimedia array, then you don’t need to use v-for unnecessarily. You can simply use:

<p v-bind:key="image" v-if="news.multimedia && news.multimedia.length">
   {{ news.multimedia[0].url }} 
</p>

Also, you can use v-if to make sure this div is only rendered if news.multimedia has a valid value and it not an empty array.

1👍

It looks like multimedia is an array of objects, so you could do: news.multimedia[0].url.

Leave a comment