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

自古美人都是妖i 提交于 2021-02-11 04:12:15

问题


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 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



来源:https://stackoverflow.com/questions/61120119/what-is-difference-between-http-get-vs-axios-get-in-vue-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!