Created
August 14, 2020 22:44
-
-
Save simonjcarr/ffc3039b9c787abb3fd89c48121f2938 to your computer and use it in GitHub Desktop.
Post.vue without the Composition API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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