Categories
Vue Answers

How to use Axios globally in all components Vue.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *