[Vuejs]-How to use npm package: axios in Laravel 5.5?

3👍

Axios is a simple promise based HTTP client. In Laravel, it is on the window object by default, so just use like so:

GET

axios.get('/some-path').then(res => {
    console.log(res.data)
})

POST

let data = {
    some: "thing"
}
axios.post('/some-path', data).then(res => {
    console.log(res.data)
})

Documentation is pretty good, as always, RTFM.


EDIT 1

If you get undefined on the axios object, use

import axios from 'axios'

at the top of your JS file and if you are entirely missing Axios, npm install axios --save

👤ggdx

1👍

in your resource/assests/js/app.js

simple add:
var axios = require(‘axios’);

since
import axios from ‘axios’
– seems to be depricated

Leave a comment