Contact form for Vue
A Vue 3 contact form component with script setup that sends submissions to your email, Telegram or Slack. No backend and no extra packages, just fetch.
Why a form backend for Vue
A Vue app built with Vite ends up as static files. To receive a contact form you'd normally need something on a server: an API, an email provider and some spam protection.
Lazyform gives you all three behind one URL. Your component posts the form and reacts to a short JSON answer. There's nothing else to deploy.
A working contact form
Replace YOUR_ACCESS_KEY with your key from /login.
<script setup>
import { ref } from 'vue'
const status = ref('idle')
const errorMessage = ref('')
async function onSubmit(event) {
status.value = 'sending'
const form = event.target
const res = await fetch('https://lazyform-api.xvelopers.com/submit', {
method: 'POST',
headers: { Accept: 'application/json' },
body: new FormData(form),
})
const data = await res.json()
if (data.success) {
status.value = 'sent'
form.reset()
} else {
status.value = 'error'
errorMessage.value = data.error.message
}
}
</script>
<template>
<p v-if="status === 'sent'">Thanks! We'll be in touch.</p>
<form v-else @submit.prevent="onSubmit">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
<input type="text" name="name" placeholder="Name" required />
<input type="email" name="email" placeholder="Email" required />
<textarea name="message" placeholder="Message" required></textarea>
<input type="checkbox" name="botcheck" class="hidden" style="display: none" />
<button type="submit" :disabled="status === 'sending'">
{{ status === 'sending' ? 'Sending…' : 'Send' }}
</button>
<p v-if="status === 'error'" role="alert">{{ errorMessage }}</p>
</form>
</template>@submit.prevent stops the page from reloading, and FormData picks up every named field, so adding a field is just adding an input.
Get submissions where you want them
You get an email for each submission. Add Telegram, Slack, Discord or WhatsApp alerts, or copy submissions into Google Sheets, Notion or Airtable. See all integrations.
Full guide
The Vue guide covers JSON bodies with v-model, validation errors, file uploads and captcha.
Questions
Does it work with Vue 2?
The example uses Vue 3 script setup. The same idea works in Vue 2: post the form data with fetch from a method and keep the status in data().
Can I use v-model instead of FormData?
Yes. Send a JSON body built from your reactive object instead, and include access_key and an empty botcheck in it. Lazyform accepts JSON bodies too.
Do I need axios?
No. The built-in fetch is enough. If your project already uses axios, post the same FormData and set the Accept header to application/json.