Question presented to candidate:
"In a Vue template I see :id, :[attrName]="value", @[eventName]="handler" and v-bind="attrs". Walk me through what each of these does and where the limits of dynamic arguments are."
What a strong answer should cover:
:is shorthand forv-bind:and@forv-on:; the part after the colon is the directive argument.- A dynamic argument in square brackets (
:[key],@[event]) computes the attribute or event name from state;nullremoves the binding. - Constraints: the expression must evaluate to a string (or null), cannot contain spaces or quotes, and in in-DOM templates the browser lowercases it.
- Same-name shorthand (Vue 3.4+):
:idmeans:id="id". v-bind="obj"with no argument spreads an object of attributes, and in Vue 3 the order relative to other attributes decides who wins.- Modifiers:
.prop(shorthand.name),.attr,.camel.
Clarifying questions expected:
- "Are these templates compiled by the build (SFCs) or written directly in the HTML page (in-DOM templates)?"
Code / implementation expected: Optional. A short template showing a dynamic attribute and event name is enough; reading the compiled output is a bonus.