Vue.js Fetch API request

Example of a simple http get Fetch request

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>

via: https://www.koderhq.com/tutorial/vue/http-fetch/