Based on the information provided in the knowledge sources, I can offer some insights into your issue with the Nuxt form behaving differently between development and production builds.
The problem you're experiencing is likely related to how the form submission is handled. In development, the onSubmit method is executed as expected, but in production, it's redirecting to the POST URL. This suggests that the default form submission behavior is not being prevented in the production build.
To address this issue, you can try the following:
-
Use useFetch instead of $fetch:
The useFetch composable is designed to work better with Nuxt's server-side rendering and client-side hydration. It ensures that data fetching is handled consistently across environments. Here's how you can modify your onSubmit function:
async function onSubmit(event: FormSubmitEvent<Schema>) {
const { data, error } = await useFetch("/api/configure", {
method: "POST",
body: JSON.stringify(state),
});
if (error.value) {
} else {
}
}
-
Explicitly prevent default form submission:
Although you mentioned that the prevent modifier didn't help, it's worth double-checking its implementation. Make sure you're using it correctly on the form element:
<UForm
:schema="formDataSchema"
:state="state"
class="space-y-4"
@submit.prevent="onSubmit"
>
-
Use the Form component's built-in submission handling:
The UForm component from Nuxt UI has built-in submission handling. Make sure you're utilizing it correctly: