0 day streak
javascript / beginner
Snippet

JavaScript Expressions in Templates

Vue templates support full JavaScript expressions inside double curly braces. This allows for simple math, string manipulation, and ternary operators.

snippet.js
javascript
1
2
3
<p>Total: {{ price + tax }}</p>
<p>Name: {{ user.name.toUpperCase() }}</p>
<p>Status: {{ items.length > 0 ? 'Active' : 'Empty' }}</p>
vue
Breakdown
1
{{ price + tax }}
Performing addition directly in the template.
2
{{ user.name.toUpperCase() }}
Calling a JavaScript method on a string variable.