--- title: Template Expressions Must Be Single Expressions impact: MEDIUM impactDescription: Using statements instead of expressions in templates causes compilation errors type: capability tags: [vue3, template, expressions, interpolation, syntax] --- # Template Expressions Must Be Single Expressions **Impact: MEDIUM** - Vue templates only support single JavaScript expressions, not statements. Using variable declarations, if statements, or multiple statements will cause template compilation errors. Template interpolation `{{ }}` and directive bindings evaluate JavaScript expressions that produce a value. Statements like `if`, `for`, variable declarations, or multi-line code blocks are not allowed. ## Task Checklist - [ ] Use only single expressions in `{{ }}` interpolation - [ ] Use ternary operators instead of if/else statements - [ ] Move complex logic to computed properties or methods - [ ] Avoid variable declarations in templates - [ ] Use `v-if`/`v-else` directives for conditional rendering **Incorrect:** ```vue ``` **Correct:** ```vue ``` ## Use Directives for Control Flow ```vue ``` ## Reference - [Vue.js Template Syntax - Using JavaScript Expressions](https://vuejs.org/guide/essentials/template-syntax.html#using-javascript-expressions) - [Vue.js Conditional Rendering](https://vuejs.org/guide/essentials/conditional.html)