Recently I began learning JavaScript and I'm encountering some confusion.
Here's the code snippet that is causing me trouble:
api.posts
.browse({ limit: 5, include: 'tags,authors' })
.then(posts => {
posts.forEach(post => {
console.log(post.title)
})
})
.catch(err => {
console.error(err)
})
While this code works perfectly fine and displays 5 post titles in the console. However, I need to implement a template like this:
<article v-for="post in posts" :key="post">
<h2>{{ post.title }}</h2>
</article>
Unfortunately, "posts" cannot be accessed as a variable. I attempted to define variables inside ".then" but ran into errors. This might seem like elementary knowledge, but I haven't found a straightforward solution yet. I appreciate any help.