[Vuejs]-Better way to loop over items in Vue?

1👍

If you don’t wanna use html tag, you can use template.
Example:

<template v-for="post in posts">
    <h1>{{ post.title }}</h1>
    <p>{{ post.author }}</p>
</template>

0👍

The way you did it is fine. Though, it is better to use list elements for this because they are more semantically correct. Then, add a :key attribute to the list items. See link for the sample: https://v2.vuejs.org/v2/guide/list.html. The page will still work if the :key attribute is included but it helps to properly re-render the list.

-1👍

you can add it in the <div>

<div v-for="post in posts">
    <h1>{{ post.title }}</h1>
    <p>{{ post.author }}</p>
</div>

Leave a comment