How to change the default base URL for Axios?

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.