[Vuejs]-Fetching data by Axios in Laravel / Vue

0👍

You are using Laravel, so axios is allready included (take a look into the require('/bootstrap') file). In your component, your export default{} is wrong. its an object, so treat it like one:

export default {
  created(){
    axios.get('/ajax')
    .then(function (response) {
      console.log(response);
    })
    .catch(function (error) {
      console.log(error);
    })
    .then(function () {
    });
  }
}

0👍

@Barbie try to add .babelrc config file

0👍

Ok, first, your syntax is wrong export default {} exports an object but your syntax is not correct.

An object syntax is key: value separated by ,

Ex:

import axios from 'axios';

export default {
  created(){
    axios.get('/ajax')
    .then(function (response) {
      console.log(response);
    })
    .catch(function (error) {
      console.log(error);
    })
    .then(function () {
    });
  }
}

P.S. I think understanding es6 modules would be helpful for you, so here is a link: https://www.sitepoint.com/understanding-es6-modules/

Leave a comment