Snippets
Use Axios globally to any component in the VueJS
Hi,
If you want to use axios
globally to any components in the VueJS, you can follow these steps:
In main.js
you can just assign Axios to $http
.
main.js
import Axios from 'axios'
Vue.prototype.$http = Axios;
By modifying the vue prototype, any vue instance will have the ability to call $http
on this.
For example-
this.$http.get('http://laravel-school.com/get')
Take a note that, the $http
is the axios object now, so any method you can call on axios object, you can call on this.$http
.
Thanks.