2016-12-27 15:57:50 +00:00
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="container">
|
|
|
|
<h1>Blog</h1>
|
|
|
|
<ul>
|
2017-11-26 13:40:57 +00:00
|
|
|
<li v-for="(post, index) in posts" :key="index">
|
2016-12-27 15:57:50 +00:00
|
|
|
<nuxt-link :to="{ name: 'posts-id', params: { id: post.id } }">{{ post.title }}</nuxt-link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p><nuxt-link to="/">Back to home page</nuxt-link></p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
export default {
|
2017-10-31 13:43:55 +00:00
|
|
|
asyncData({ req, params }) {
|
2016-12-27 15:57:50 +00:00
|
|
|
// We can return a Promise instead of calling the callback
|
|
|
|
return axios.get('https://jsonplaceholder.typicode.com/posts')
|
2017-10-31 13:43:55 +00:00
|
|
|
.then((res) => {
|
|
|
|
return { posts: res.data.slice(0, 5) }
|
|
|
|
})
|
2017-08-03 08:47:19 +00:00
|
|
|
},
|
|
|
|
head: {
|
|
|
|
title: 'List of posts'
|
2016-12-27 15:57:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.container {
|
|
|
|
width: 70%;
|
|
|
|
margin: auto;
|
|
|
|
text-align: center;
|
|
|
|
padding-top: 100px;
|
|
|
|
}
|
|
|
|
ul {
|
|
|
|
list-style-type: none;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
ul li {
|
|
|
|
border: 1px #ddd solid;
|
|
|
|
padding: 20px;
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
ul li a {
|
|
|
|
color: gray;
|
|
|
|
}
|
|
|
|
p {
|
|
|
|
font-size: 20px;
|
|
|
|
}
|
|
|
|
a {
|
|
|
|
color: #41B883;
|
|
|
|
}
|
|
|
|
</style>
|