Premium

Contact Form (Single File Component + Fetch)

By FrontendAtlas Team · Updated Jan 30, 2026

Build a contact form in a Vue 3 single file component using the Composition API. You will only work inside in App.vue. The template and styles are already provided for you. Validate the user's input and send the form data with a POST request to…

  • Use Vue 3's Composition API in a single-file component (App.vue).
  • Use refs to track form fields: name, email, and message.

What you’ll build / What this tests

This premium vue coding focuses on Contact Form (Single File Component + Fetch). You’ll apply vue and forms thinking with intermediate level constraints. The prompt emphasizes Build a contact form in a Vue 3 single file component using the Composition API. You….

Learning goals

  • Translate the prompt into a clear vue API signature and return shape.
  • Apply vue, forms, http techniques to implement contact form (single file component + fetch).
  • Handle intermediate edge cases without sacrificing readability.
  • Reason about time/space complexity and trade-offs in vue.

Key decisions to discuss

  • Define the exact input/output contract before coding.
  • Prioritize predictable edge-case handling over micro-optimizations.

Evaluation rubric

  • Correctness: covers required behaviors and edge cases.
  • Clarity: readable structure and predictable control flow.
  • Complexity: avoids unnecessary work for large inputs.
  • API discipline: no mutation of inputs; returns expected shape.
  • Testability: solution is easy to unit test.

Constraints / Requirements

  • Use Vue 3's Composition API in a single-file component (App.vue).
  • Use refs to track form fields: name, email, and message.
  • Make all fields required; validate email with a basic email pattern and require a minimum length for the…
  • Disable the submit button while the form is invalid or while a request is in progress.
  • On submit, send a POST request with the form body to https://jsonplaceholder.typicode.com/posts.
  • Show a success message if the request succeeds and an error message if it fails.
  • Initially, the submit button is disabled until all fields are valid.
  • If the user attempts to submit invalid data, validation error messages are shown for the affected fields once…
  • On a valid submit, a POST request is sent and the button is disabled while the request is…
  • On success, show the message: "Your message has been sent. Thank you!" and optionally reset the form.

Mini snippet (usage only)

// Example usage
const input = /* contact form (single file component + fetch) input */;
const result = solve(input);
console.log(result);

// Edge case check
const empty = input ?? null;
const fallback = solve(input);
console.log(fallback);

// Expected: describe output shape, not the implementation
// (no solution code in preview)

Common pitfalls

  • Mutating inputs instead of returning a new value.
  • Skipping edge cases like empty input, duplicates, or nulls.
  • Overlooking time complexity for large inputs.

Related questions

Upgrade to FrontendAtlas Premium to unlock this challenge. Already upgraded? Sign in to continue.