Nuxt/examples/async-data/pages/post.vue

42 lines
699 B
Vue
Raw Normal View History

<template>
<div>
<p>{{ post.title }}!</p>
2016-12-23 12:09:14 +00:00
<post post-id="1" />
<post post-id="2" />
2016-12-16 17:12:38 +00:00
<p><nuxt-link to="/">Back home</nuxt-link></p>
</div>
</template>
<script>
const axios = require('axios')
2016-12-23 12:09:14 +00:00
import Post from '~components/post'
export default {
2016-11-07 13:12:59 +00:00
data ({ req }) {
// We can return a Promise instead of calling the callback
return axios.get('https://jsonplaceholder.typicode.com/posts/1')
.then((res) => {
return { post: res.data }
2016-11-07 13:12:59 +00:00
})
},
head () {
return {
title: this.post.title
}
2016-12-23 12:09:14 +00:00
},
components: {
Post
}
}
</script>
2016-11-07 13:12:59 +00:00
<style scoped>
p {
font-size: 20px;
text-align: center;
padding: 100px;
2016-11-07 13:12:59 +00:00
padding-bottom: 0;
}
</style>