Why does using beforeFetch cause a POST request to become a GET request? #4677
Replies: 1 comment
-
Hey @PeiTianHuang! 👋 I'm here to help you with any bugs or questions you have. I can also assist you in becoming a contributor. It seems like you're encountering an issue where using In the return useFetch(
url.startsWith('http') ? url : `${baseURL}${url}`,
{
...fetchOptions,
async beforeFetch({ options }) {
options.method = 'POST'; // Ensure the method is explicitly set
return { options };
},
}
) This ensures that the method remains as POST when To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The value of fetchOptions is as follows:
{ "method": "POST", "body": "{\"dates\":[\"2025-03-17T02:41:31.375Z\",\"2025-03-24T02:41:31.375Z\"],\"pageName\":\"\",\"pageSize\":10,\"currentPage\":1,\"total\":100,\"data\":[]}", "headers": { "Content-Type": "application/json" } }
If I don't set beforeFetch, the request I'm initiating at this moment is a POST request
return useFetch( url.startsWith('http') ? url :
${baseURL}${url}, { ...fetchOptions, } )
But if I set beforeFetch, a GET request will be initiated regardless of whether the returned option is the same as fetchOptions
return useFetch( url.startsWith('http') ? url :
${baseURL}${url}, { ...fetchOptions, async beforeFetch({ url }) { return { url, fetchOptions } }, } )
Beta Was this translation helpful? Give feedback.
All reactions