v-text
v-text updates the element's text content. It is a one-way binding from a reactive property to the DOM.
Basic Usage
html
<div v-scope="{ msg: 'Hello' }">
<span v-text="msg"></span>
</div>Comparison with Mustache Syntax
v-text is equivalent to using mustache interpolations ().
html
<span v-text="msg"></span>
<!-- is the same as -->
<span>{{ msg }}</span>Why use v-text?
While mustache syntax is generally more flexible, v-text can be useful in specific cases:
- Avoiding FOUC: When using mustache syntax, the raw
may be visible for a split second before pocket-vue initializes. Usingv-texton an empty element avoids this flash of uncompiled content (you can also usev-cloakto solve this). - Overwriting Content:
v-textwill completely overwrite all children inside the target element, whereas mustache syntax allows you to combine static text and reactive data within a single element.
Details
v-text works by setting the element's textContent property. This means all values are treated as plain text and will not be interpreted as HTML.
html
<div v-scope="{ msg: '<b>Bold</b>' }">
<!-- Renders as: <b>Bold</b> -->
<span v-text="msg"></span>
</div>