Skip to content

Instantly share code, notes, and snippets.

@simonjcarr
Created August 15, 2020 14:40
Show Gist options
  • Select an option

  • Save simonjcarr/b5ad97f62cc6f3798a7e175abecd9cd8 to your computer and use it in GitHub Desktop.

Select an option

Save simonjcarr/b5ad97f62cc6f3798a7e175abecd9cd8 to your computer and use it in GitHub Desktop.
<template>
<div class="text-4xl font-bold mb-4">My Blog Roll</div>
<div v-for="post in posts" :key="post.id">
<div class="bg-gray-200 mb-4 shadow p-2 rounded">
<div class="text-2xl font-semibold"><router-link :to="`/post/${post.id}`">{{ post.title }}</router-link></div>
<div class="mt-2 bg-gray-400 p-2 text-gray-700 rounded">{{ post.body }}</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
posts: []
};
},
methods: {
fetchPosts() {
fetch("https://jsonplaceholder.typicode.com/posts")
.then(response => response.json())
.then(data => (this.posts = data));
}
},
mounted() {
this.fetchPosts();
}
};
</script>
<style></style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment