Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upHow to set query params and message body? #97
Comments
This comment has been minimized.
This comment has been minimized.
|
Hey. Exactly with this module's plugin you can use the same functions of original axios library to make requests: const { data } = await this.$axios.post(endpoint, { data: { }, query: { } })We also provide some optional helpers with exactly same params as original axios but they directly return data. So no destructuring like const foobar = await this.$axios.$post(endpoint, { data: { }, query: { } }) |
This comment has been minimized.
This comment has been minimized.
|
Thanks! I just found the actual issue. Nuxt-Axios didn't like that some endpoints already included a query param (eg. "?foo=bar") in their url. Axios itself just appends the additional query params, but Nuxt-Axios expects that the url itself doesn't contain any query. For my case it's no big deal, but maybe you want to adjust that in a future release. :) |
This comment has been minimized.
This comment has been minimized.
|
@Flur3x Thanks for your reports. Would you please provide some example to reproduce that error? (Also do you mean with original axios, |
This comment has been minimized.
This comment has been minimized.
|
No, I don't mean the baseURL, but the url path. As an example, let's say I have the following call: const params = {
articleNumber: this.articleNumber,
};
const response = await axios.$get('/api/slider?mode=bestseller', { params });Axios sets both query params, but Nuxt-Axios only sets const params = {
articleNumber: this.articleNumber,
mode: 'bestseller',
};
const response = await axios.$get('/api/slider', { params }); |
This comment has been minimized.
This comment has been minimized.
Somehow impossible if this module has a different behavior than original axios. axios-module/lib/plugin.template.js Line 39 in caa7b96 Will keep this issue open until make sure about it. And make any fix if possible. |
This comment has been minimized.
This comment has been minimized.
|
Okay, thanks. I also tried it without the wrapper (get() instead of $get()) with the same result. |
This comment has been minimized.
This comment has been minimized.
|
Any news about this issue ? I have the same problem. |
This comment has been minimized.
This comment has been minimized.
|
Hi, Im newbie on nuxt and im dealing with axios. let data = { name :. "test" } axios.post(url, data, { But on request, im passing a json stringify. Thanks |
This comment has been minimized.
This comment has been minimized.
|
I am not sure if this is the correct answer but this is how I make it work for me.
If I do that, using 'params' , I mean putting my object into another object with params, I can read that object using $_GET in the backend I hope this information helps someone :D |
This comment has been minimized.
This comment has been minimized.
|
Same issue. Second argument object with |
This comment has been minimized.
This comment has been minimized.
|
So, it's not possible in Axios. Or change your API to use req.query ou change your front to use http |
This comment has been minimized.
This comment has been minimized.
Can we also use this to send formData (any file to upload) here along with query params. As per my limited knowledge, formData goes as separate object and below syntax is not not working for me |
This comment has been minimized.
This comment has been minimized.
|
@pi0 Hi! Why POST request to api not sent data(body)?
|
This comment has been minimized.
This comment has been minimized.
Hi man, Can this be done with authentication? The credentials are on env file. I'm using SSR nuxt. Excuse my bad english. |


Hey,
I've tried to figure out how to send payload like query params and message body, like I was used with the original Axios library. There I could just add a second argument (payload) in the method call.
Am I overseeing something? I'm quite sure I'am. Thanks for your help and for this module. :)
Best,
Daniel