[Vuejs]-How to send JSON Data as response in Vue.js 2?

0👍

There are many times when building application for the web that you may want to consume and display data from an API. There are several ways to do so, but a very popular approach is to use axios, a promise-based HTTP client.

Basic example

new Vue({
  el: '#app',
  data () {
    return {
      info: null
    }
  },
  mounted () {
    axios
      .get('https://api.coindesk.com/v1/bpi/currentprice.json')
      .then(response => (this.info = response))
  }
})
<div id="app">
  {{ info }}
</div>

-1👍

Take a look at “axios”, a very popular and simple library for making HTTP requests – https://github.com/axios/axios. Read the documentation how to use it 🙂

Example of a GET request with axios:

import axios from 'axios'; // ES6

axios.get('/api/**')
  .then(response => console.log(response.data));

Leave a comment