Sometimes, we want to use Axios globally in all components Vue.js.
In this article, we’ll look at how to use Axios globally in all components Vue.js.
How to use Axios globally in all components Vue.js?
To use Axios globally in all components Vue.js, we can add axios
into the Vue
prototype.
For instance, we write
import axios from 'axios'
Vue.prototype.$http = axios ;
in main.js
so that all Vue component instances will have this.$http
set to axios
.
Conclusion
To use Axios globally in all components Vue.js, we can add axios
into the Vue
prototype.