Question presented to candidate:
"We have a sign-up form with a name field, a bio textarea, a terms checkbox, topping checkboxes, a size radio group and a country dropdown. Explain how v-model keeps each of these in sync with component state, and what it actually does under the hood."
What a strong answer should cover:
v-modelis two-way binding sugar: it writes state into the element and listens for the element's event to write back.- The property and event differ by element: text and textarea use
value+input; checkbox and radio usechecked+change; select usesvalue+change. - A single checkbox binds a boolean (or
true-value/false-value); several checkboxes bound to one array collect theirvalues; a multiple select binds an array. v-modelignores the initialvalue,checkedorselectedattributes: state is the single source of truth.- Text inputs wait for IME composition to finish before updating.
- It compiles to a runtime directive (
vModelText,vModelCheckbox, ...) plus anonUpdate:modelValuehandler; the expression must be assignable.
Clarifying questions expected:
- "Should the field update on every keystroke or only on blur?" (leads into modifiers)
- "Is any of these a custom component rather than a native element?"
Code / implementation expected: Yes. A form with at least a text input, a checkbox group and a select, showing the bound state.