Skip to content

Instantly share code, notes, and snippets.

@simonjcarr
Created August 14, 2020 22:44
Show Gist options
  • Select an option

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

Select an option

Save simonjcarr/ffc3039b9c787abb3fd89c48121f2938 to your computer and use it in GitHub Desktop.
Post.vue without the Composition API
<template>
<div>
<div class="text-4xl font-bold">{{ post.title }}</div>
<div>{{ post.body }}</div>
<div class="italic mt-4">Author: <span class="text-red-500">{{ user.name }}</span></div>
</div>
</template>
<script>
export default {
data() {
return {
post: {},
user: {}
};
},
methods: {
fetchPost() {
fetch(
`https://jsonplaceholder.typicode.com/posts/${this.$route.params.id}`
)
.then(response => response.json())
.then(data => (this.post = data))
.then(() => {
fetch(
`https://jsonplaceholder.typicode.com/users/${this.post.userId}`
)
.then(response => response.json())
.then(data => (this.user = data));
});
}
},
mounted() {
this.fetchPost();
}
};
</script>
<style></style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment