Skip to content

Instantly share code, notes, and snippets.

@larizzatg
Last active July 21, 2021 16:38
Show Gist options
  • Save larizzatg/09bb170ec12e158a6405db10ad67f2c4 to your computer and use it in GitHub Desktop.
Save larizzatg/09bb170ec12e158a6405db10ad67f2c4 to your computer and use it in GitHub Desktop.
Nuxt: Getting data, asyncData
<template>
<div>
<h1>Post</h1>
<div v-if="post" id="first-post">
<h3 class="text-lg">{{ post.title }}</h3>
<p class="text-base">{{ post.body }}</p>
</div>
</div>
</template>
<script>
export default {
async asyncData({ $axios }) {
console.log('async data ');
const { data } = await $axios.get('https://jsonplaceholder.typicode.com/posts/1');
return { post: data };
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment