Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Vue 3 v-text Directive

Vue 3 v-text Directive

Vue3 Built-in Directives Vue 3 Built-in Directives


v-text The directive is used to update an element's text content, equivalent to setting the DOM element's textContent attribute.


Basic Explanation

v-text The directive sets the value of its bound expression as the element's text content. It is the most commonly used text interpolation {{ }} 's alternative syntax.


Basic Usage

Example

{{ message }}

Example


Difference Between v-text and Braces

v-text and {{ }} The main difference from brace interpolation is:

Example

the original text is overwritten

prefix {{ message }} suffix


Use Cases

1. Simple Text Binding

When you only need to display text without mixing in other content, v-text is a clear choice:

Example

2. Used together with v-once

v-text can be used together with v-once, rendering only once and not updating afterward:

Example


Notes

Overwrite existing content: v-text completely overwrites all text content inside the element. If you only need to update part of the text, you should use mustache interpolation. {{ }}.

HTML escaping: v-text treats content as plain text and does not parse HTML tags. If you need to render HTML, you should use the v-html directive.

Example


Vue3 Built-in Directives Vue 3 Built-in Directives