Docs / Frameworks
Contact form for Vue and Nuxt
A single-file component for Vue 3 or Nuxt that posts with fetch and shows the result inline.
<!-- ContactForm.vue (Vue 3 / Nuxt) -->
<script setup>
import { ref } from "vue";
const status = ref("idle");
async function onSubmit(e) {
const form = e.target;
status.value = "sending";
try {
const res = await fetch("https://wrenform.com/f/YOUR_FORM_ID", {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(form),
});
status.value = res.ok ? "sent" : "error";
if (res.ok) form.reset();
} catch {
status.value = "error";
}
}
</script>
<template>
<form @submit.prevent="onSubmit">
<label>Name <input type="text" name="name" autocomplete="name" required /></label>
<label>Email <input type="email" name="email" autocomplete="email" required /></label>
<label>Message <textarea name="message" required></textarea></label>
<input type="text" name="_honey" style="display:none" tabindex="-1" autocomplete="off" />
<button type="submit" :disabled="status === 'sending'">Send</button>
<p role="status">
<span v-if="status === 'sent'">Thanks, your message was sent.</span>
<span v-if="status === 'error'">Something went wrong. Please try again.</span>
</p>
</form>
</template>Steps
- Create a form and copy its form ID, or let your AI tool create one without an account.
- Save the component as
ContactForm.vue(incomponents/for Nuxt, so it's auto-imported) and replaceYOUR_FORM_ID. - Use it on a page:
<ContactForm />. In Nuxt, createpages/contact.vuefor a/contactroute. - Deploy. Then add your site's origin under Allowed origins in the form's settings.
No server route needed. In Nuxt you don't need a server/api handler: the browser posts straight to Wrenform. The form ID is public by design.
On Nuxt, the Nuxt guide has a component that posts with $fetch and works before hydration. In Nuxt you can keep the ID in runtimeConfig.public. In plain Vue with Vite, use import.meta.env.VITE_WRENFORM_ID.
Without JavaScript
A plain <form action="https://wrenform.com/f/YOUR_FORM_ID" method="POST"> also works in any Vue template, including statically generated Nuxt pages. Visitors leave the page and come back through a redirect. See redirects.
Test it
Run the dev server, open the page and send the form. You should see the thank-you line, the submission in your dashboard and an email. While testing locally, leave Allowed origins empty or add your dev origin, such as http://localhost:3000.
Common problems
- CORS error. The page's origin isn't in the form's allowed origins.
empty_submission. The inputs neednameattributes.v-modelalone doesn't add them.- Hydration mismatch warning in Nuxt. A browser extension changed the form. It doesn't affect the submission.
- Strict CSP. Add
connect-src https://wrenform.com.
Next steps
- My form isn't working: symptom, cause and fix.
- Spam: the timing field and Turnstile.
- Fields: reserved fields, subjects and reply-to.
- Errors: every code and its fix.