Skip to content
Lazyform
Docs menu

Frameworks and builders

Vue

Build a Vue 3 contact form with script setup that posts to Lazyform, with loading, success and error states.

This guide shows a Vue 3 single-file component that sends submissions to Lazyform. It uses <script setup> and works in any Vite-based Vue app.

Before you start

Get an access key: type your email on the homepage for an instant key, or sign in and create a form. Replace YOUR_ACCESS_KEY with your key (it starts with lf_).

The minimal form

A regular form posts to Lazyform and the visitor sees a thank-you page.

ContactForm.vue
<template>
  <form action="https://lazyform-api.xvelopers.com/submit" method="POST">
    <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" tabindex="-1" autocomplete="off" />
    <button type="submit">Send</button>
  </form>
</template>

With fetch and inline messages

ContactForm.vue
<script setup>
import { reactive, ref } from 'vue';

const fields = reactive({ name: '', email: '', message: '', botcheck: false });
const status = ref('idle'); // idle | sending | success | error
const error = ref('');

async function submit() {
  status.value = 'sending';
  error.value = '';

  try {
    const response = await fetch('https://lazyform-api.xvelopers.com/submit', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
      body: JSON.stringify({
        access_key: 'YOUR_ACCESS_KEY',
        name: fields.name,
        email: fields.email,
        message: fields.message,
        botcheck: fields.botcheck ? 'on' : '',
      }),
    });
    const result = await response.json();

    if (result.success) {
      status.value = 'success';
      Object.assign(fields, { name: '', email: '', message: '' });
    } else {
      status.value = 'error';
      error.value = result.error?.message ?? 'Something went wrong.';
    }
  } catch {
    status.value = 'error';
    error.value = 'Network error. Please try again.';
  }
}
</script>

<template>
  <p v-if="status === 'success'">Thanks! Your message has been sent.</p>
  <form v-else @submit.prevent="submit">
    <input v-model="fields.name" type="text" placeholder="Name" required />
    <input v-model="fields.email" type="email" placeholder="Email" required />
    <textarea v-model="fields.message" placeholder="Message" required></textarea>
    <input v-model="fields.botcheck" type="checkbox" class="hidden" style="display: none" tabindex="-1" autocomplete="off" />
    <button type="submit" :disabled="status === 'sending'">
      {{ status === 'sending' ? 'Sending...' : 'Send' }}
    </button>
    <p v-if="status === 'error'" role="alert">{{ error }}</p>
  </form>
</template>

The honeypot is bound with v-model and sent as botcheck. People never see it, so it stays empty. If a bot ticks it, Lazyform answers like a success but files the submission as spam.

Tips

  • Environment variables. Use import.meta.env.VITE_LAZYFORM_KEY instead of the hard-coded key. The key is safe to be public; it only allows submitting to your form.
  • Files. Use a template ref on the form and send new FormData(formRef.value) with only the Accept header. See File uploads.
  • Extra fields. Any key you add to the JSON body is stored and delivered in the order you send it.

Where to go next