Vue Basic Syntax
Vue's template syntax is based on standard HTML. This means all Vue templates are valid HTML and can be parsed by all standard browsers. Internally, Vue compiles templates into efficient, virtual DOM render functions. Combined with the reactivity system, when application state changes, Vue can intelligently calculate the minimum set of components that need re-rendering and apply the minimal number of DOM operations.
Text Interpolation
The most basic form of data binding is text interpolation, which uses "Mustache" syntax (double curly braces):
The content inside the double curly braces will be replaced with the value of the msg variable. When msg's value changes, this content will also update automatically.
You can also use any valid single JavaScript expression inside the double curly braces:
Raw HTML
Double curly braces interpret data as plain text, not HTML. To output real HTML, you need to use the v-html directive:
Security Warning: Dynamically rendering arbitrary HTML on your website is very dangerous because it can easily lead to XSS (Cross-Site Scripting) attacks. Please use v-html only when you completely trust the content. Never use v-html to render user-submitted content.
Attribute Binding
Double curly brace syntax cannot be used in HTML attributes. To bind dynamic values to attributes, we need to use the v-bind directive:
Because v-bind is very commonly used, it has a dedicated shorthand syntax, a colon (:):
Using JavaScript Expressions
For all data binding, Vue supports full JavaScript expression capabilities. This means you can perform calculations, call methods, etc. in templates.
Limitation: Each binding can only contain a single expression. Statements like let a = 1 are invalid. Additionally, the expression's access scope is limited to the current component instance's properties and methods, and cannot access global variables.