axios-module: base url is not working
Hi,
please help me on my nuxt.config.js
axios: {
// See https://github.com/nuxt-community/axios-module#options
baseURL: environment.API_URL,
requestInterceptor: (config, {store}) => {
config.headers.common['Authorization'] = '';
config.headers.common['Content-Type'] = 'application/x-www-form-urlencoded;application/json';
return config
}
},
and for my actions
return axios.post('/verify/phone', querystring.stringify(phoneData))
.then(
data => {
commit('SET_MOBILE', phoneData);
return {
valid : true,
data : data
}
},
data => {
return {
valid : false,
data : data
}
}
);
but for the request it request on the localhost http://localhost:3000/verify/phone
<div align="right">This question is available on Nuxt.js community (#c118)</div>About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 30
Just double check that the variable is named
baseURLrather thanbaseUrl. That one got me for a while.in nuxt.config.js
use like this.
But actually, I have this problem. As a begginer in nuxt, I tried to use nuxt-axios and it does not work. I spent time looking on how to configure it if I dont have โhardcodedโ hostโฆ And I failed. This is more strange that if I use just axios - it works out of the box. Maybe somebody knows how to make nuxt-axios work in such situations? Upd: Actually, I found the solution:
Make it works
Why are you not using
this.$auth.loginWith?? It sets the token and cookie for you, then fetches and sets the user details (onthis.$auth.user). Check the example!Demo: https://github.com/nuxt-community/auth-module/tree/dev/examples/demo
Api: https://github.com/nuxt-community/auth-module/tree/dev/examples/api
Good luck ๐
ะะััััััััััััััััั ัั
If you do not use arrow functions, you can access
axiosfrom this:You can find an example here: https://axios.nuxtjs.org/usage.html#store-actions
This way you do not have to use axios as a plugin.
use
this.$axiosinstead ofaxiosNone of the above works unfortunately. NuxtJS/Axios, all request stay localhost instead of using the value in baseURL.
This is AWESOME! Now what I am sure is that I am blind haha ๐คฃ
in nuxt.config.js, instead of:
modules: [ '@nuxtjs/axios', ], axios: { baseURL: 'https://yourapi.com' }use it:
modules: [ ['@nuxtjs/axios', { baseURL: 'https://yourapi.com' }] ],You should declare your baseURL without
[]If you want to use it in a plugin, you can read more about how to use the env property here: https://nuxtjs.org/api/configuration-env/Personally i just directly set the baseUrl in
nuxt.config.jsforAxioslike so: