Vue.js uses an HTML-based template syntax.
This syntax allows you to declaratively bind the rendered DOM to the underlying Vue instance's data.
All Vue templates are syntactically valid HTML that can be parsed by specification-compliant browsers.
The most basic form of data binding is text interpolation using the "Mustache" syntax (double curly braces).
The mustache tag {{ msg }} will be replaced with the value of the msg property from the data object.
It will also automatically update whenever the msg property changes.
<span>Message: {{ msg }}</span>
The double mustaches interpret data strictly as plain text, not HTML.
If your data variable contains actual HTML tags that you want rendered, you must use the v-html directive.
<p>Using text interpolation: {{ rawHtml }}</p>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
Warning: Dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to XSS vulnerabilities. Only use v-html on trusted content!
Inside the mustache tags, you are not limited to just variable names.
Vue supports the full power of standard JavaScript expressions.
You can perform math, run string methods, and use ternary operators directly inside the template.
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
The only restriction is that each binding can only contain exactly one single expression.
What is the visual syntax used for basic text interpolation in Vue templates?
How do you output actual rendered HTML tags from a data variable, rather than plain text?