问题
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?
回答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
回答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 carryingimport axios from './my-axios-instance'
everywhere, this is particularly useful in non-modular environments or when baseaxios
is refactored toaxios.create()
instance at some pointAxios instance can be swapped for a hierarchy of Vue components, e.g. configured with different base URL or headers for a feature module
来源:https://stackoverflow.com/questions/61120119/what-is-difference-between-http-get-vs-axios-get-in-vue-js