Categories
Vue Answers

How to change the default base URL for Axios?

Spread the love

Sometimes, we want to change the default base URL for Axios.

In this article, we’ll look at how to change the default base URL for Axios.

How to change the default base URL for Axios?

To change the default base URL for Axios, we can set the baseUrl option when we’re calling our axios instance.

For instance, we write

this.$axios({ url: "items", baseURL: "http://new-url.com" });

to call this.$axios with an object with the baseURL to a different URL than the one that’s set when we’re creating the axios instance.

Conclusion

To change the default base URL for Axios, we can set the baseUrl option when we’re calling our axios instance.

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 *