Make a simple Fetch get request in Vue.js and display data:
<template>
<div v-for="post in posts" v-bind:key="userId">
<h2>{{ post.title }}</h2>
<p>{{ post.body }}</p>
</div>
</template>
<script>
export default {
data() {
return {
posts: []
}
},
methods: {
getPosts() {
fetch('https://jsonplaceholder.typicode.com/posts/')
.then(response => response.json())
.then(data => this.posts = data)
}
},
mounted() {
this.getPosts()
}
}
</script>