What is difference between $http.get() vs axios.get() in vue.js?

Viewed 699

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. Can anyone help me please?

2 Answers

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

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

Related