axios in vue js code example

Example 1: axios in vue

//Install Axios
npm install axios

//Import Axios in .vue file
import axios from 'axios'

//Add a method to implement Axios
testMethod () {
      axios.post('URL')
      .then(function (response) {
        alert (response.data);
      })
      .catch(function (error) {
        alert(error);
      });
    }

Example 2: how to use axios in vue

//Install Axios from terminal
npm install axios
//Import Axios in your HelloWorld.vue
import axios from 'axios'
//Add a method to implement Axios
test () {
      axios.post('URL')
      .then(function (response) {
        alert (response.data);
      })
      .catch(function (error) {
        alert(error);
      });
    }

Example 3: install axios vue

//Install Axios from terminal
npm install axios

Example 4: vuejs list items from axios

  • {{food.name}}

    • {{nutrient.nutrient_id}}
axios.get(url).then(response => { this.foods = response.data.report.foods })

Example 5: axios vuejs

axios
  .get('https://api.coindesk.com/v1/bpi/currentprice.json')
  .then(response => (this.info = response.data.bpi))

Tags:

Misc Example