How to get axios baseUrl in nuxt? How to get axios baseUrl in nuxt? vue.js vue.js

How to get axios baseUrl in nuxt?


If in nuxt.config.js you defined:

axios: {  baseURL:"localhost:4040/api/"}

All you need to do for the image is to point to it as follows:

:src="`${$axios.defaults.baseURL}upload/1.png`"


You can access axios config like this to get your api base URL:

this.$axios.defaults.baseURL


In case if someone is wondering how to make an axios baseURL domain-independent:

Here is how simply it can be achieved:

axios: {  baseURL: '/'}

It will work on localhost:3000/api as well as on any-domain.com/api