Question presented to candidate:
"Look at a Vue template for the first time: double curly braces, attributes starting with v-, colons and at-signs. Explain what Vue template syntax is and what you are allowed to write inside it."
What a strong answer should cover:
- Templates are valid HTML extended with Vue syntax, and are compiled into JavaScript render functions, not interpreted at runtime as strings.
- Text interpolation
{{ expr }}puts a value into text and always escapes HTML; raw HTML needsv-html. - Directives are
v-attributes with the anatomyv-name:argument.modifier="value"; shorthands:forv-bind,@forv-on,#forv-slot; dynamic arguments:[name]; the Vue 3.4 same-name shorthand:id. - Bindings accept one JavaScript expression: arithmetic, ternaries, method calls, template literals. Statements like
let,iforforare compile errors. - Expressions see the component's state plus a restricted allowlist of globals (such as
MathandDate), notwindow. - Mustaches do not work inside HTML attributes; use
v-bindinstead.
Clarifying questions expected:
- "Should I cover only the template side, or also how it compiles to a render function?"
Code / implementation expected: Optional. A short template showing interpolation, a bound attribute and an event, and ideally one compile error.