Question presented to candidate: "Build the sign-up form for our app: email, age, password and a terms checkbox. Errors should not shout at users before they have typed anything, the button must not double-submit, and the server can still reject an email that is taken. How do you handle forms and validation in Vue?"
What a strong answer should cover:
v-modelon inputs (with.trim,.number,.lazy), one reactive form object, and@submit.preventon a real<form>.- Validation as derived state: an
errorscomputed from the current values, never a second copy that can drift;isValidcomputed from it. - When to show errors: after blur (touched) or after the first submit attempt, not on the first keystroke.
- Submit handling: block when invalid, a
submittingflag to disable the button, and mapping server-side errors back to the field or a form message. - Edge cases:
.numbergives""when the field is cleared, the browser's own validation (novalidate), and accessibility (aria-invalid, error text linked to the input). - When a library pays off: VeeValidate (or FormKit) for many forms, schema validation, field arrays and consistent touched/dirty tracking.
Clarifying questions expected:
- "Is the same validation needed on the server, and can we share a schema?"
- "How many forms like this will the app have?"
Code / implementation expected: Yes β a small form with computed errors, touched state and an async submit.