I recently created something new for myself, but I encountered a problem. Let me explain further.
The component is named components/HomeComponent.vue
Here is the code:
HomeComponent.vue
<script>
export default {
name: "HomeComponent",
data() {
posts: [
{ title: "Hello", body: "Some text" },
{ title: "Hello", body: "Some text" },
{ title: "Hello", body: "Some text" },
{ title: "Hello", body: "Some text" }
];
}
};
</script>
and I have my "view" views/Home.vue
Home.vue
<template>
<!-- Blog Entries Column -->
<div class="col-md-8">
<h1 class="my-4">Статии</h1>
<!-- Blog Post -->
<div class="card mb-4" v-for="post in posts">
<div class="card-body">
<h2 class="card-title">{{ post.title }}</h2>
<p class="card-text">{{ post.body }}</p>
<a href="#" class="btn btn-primary">Read More →</a>
</div>
<div class="card-footer text-muted">
Posted on January 1, 2017 by
<a href="#">xxx</a>
</div>
</div>
</div>
</template>
I need to access the posts in my Home.vue
file and create a loop. Can anyone provide guidance on how to do this? Thank you in advance! :)
<script>
// @ is an alias to /src
import HomeComponent from "@/components/HomeComponent.vue";
export default {
name: "home",
components: {
HomeComponent
},
};
</script>