Skip to content Skip to sidebar Skip to footer

What Is Difference Between $http.get() Vs Axios.get() In Vue.js?

I have get little bit confused to understand the main difference between $http.get() and axios.get(). I have checked out many resources but I did not get any satisfactory answers.

Solution 1:

The $http is a global variable probably you defined in your vuejs project, please search for $http in your project and you might find it's just the implementation of axios, which will give you an easy access to your axios library with global configuration.

axios is a library which capable of sending and receiving Http requests check it here axios library.

so in short answer they are the same

Solution 2:

As it can be seen in source code, the only thing that vue-axios plugin does is providing $http property for Vue instance and components that use it.

This is a form of dependency injection and serves two purposes:

  • this.$http can be accessed inside Vue components instead of carrying import axios from './my-axios-instance' everywhere, this is particularly useful in non-modular environments or when base axios is refactored to axios.create() instance at some point

  • Axios instance can be swapped for a hierarchy of Vue components, e.g. configured with different base URL or headers for a feature module

Post a Comment for "What Is Difference Between $http.get() Vs Axios.get() In Vue.js?"