2.7. Vue3 template syntax

发布时间 : 2025-10-25 13:33:37 UTC      

Page Views: 9 views

Vue uses HTML-based template syntax, which allows developers to declaratively bind DOM to the data of the underlying Vue instance.

The core of Vue is a system that allows you to use concise template syntax to declaratively render data into DOM.

Combined with the response system, when the application state changes, Vue can intelligently calculate the minimum cost of re-rendering components and apply it to DOM operations.

2.7.1. Interpolation.

2.7.2. Text

The most common form of data binding is to use the {{...}} text interpolation (double curly braces):

Text interpolation

<divid="app"><p>{{ message }}p>div>    

The content of the {{...}} tag will be replaced with the value of the message attribute in the corresponding component instance. If the value of the message attribute changes, the content of the {{...}} tag will also be updated.

If you do not want to change the contents of the tag, you can use the v-once the instruction performs one-time interpolation, and when the data changes, the contents of the interpolation are not updated.

<span v-once>This will not change: {{ message }}span>      

2.7.3. Html

Use v-html instruction is used for output html code:

v-html instruction

<divid="example1"class="demo"><p>Text interpolation using double curly braces: {{ rawHtml }}p><p>Use v-html Order:<spanv-html="rawHtml">span>p>div><script>const RenderHtmlApp = { data() { return { rawHtml: ' red">This will display red!' } } } Vue.createApp(RenderHtmlApp).mount('#example1')script>      

2.7.4. Attribute

The value in the HTML property should use the v-bind instructions.

<div v-bind:id="dynamicId">div>    

For Boolean attributes, the regular values are either true or false . If the attribute value is null or undefined , the attribute will not be displayed.

<button v-bind:disabled="isButtonDisabled">buttonbutton>    

If in the above code isButtonDisabled the value of null or undefined , then disabled properties are not even included in the rendered