v-text Text Content Directive

Last updated: 2026-10-22

v-text Text Content Directive

v-text sets the element's textContent from the expression. It equals mustache interpolation but replaces the whole content of the element.

GroupDirectives
KindDirective
ScopeTemplate
Vue Version3.0+
SSR SupportYes

📝 Syntax

<p v-text="msg"></p>

<p v-text="msg"></p>
<!-- equivalent to -->
<p>{{ msg }}</p>

⚙️ Arguments

expressionAny expression; the result is stringified into the element text

Returns:Directive, no return value

▶ Example

Edit the code below and see the live result:

Output:

Both paragraphs show Hello Vue! — v-text behaves exactly like interpolation.

💡 Key Points

ℹ️ Note v-text overwrites existing content; prefer {{ }} when you only need partial interpolation.
💡 Tip The value is plain text — HTML tags are not parsed (use v-html for that).
⚠️ Warning v-text shares {{ }}'s escaping, so HTML in data shows literally — good against XSS.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q How is v-text different from mustache interpolation?
A Identical output; v-text replaces the whole element content while {{ }} only fills its position, making interpolation more flexible in mixed text.
Q Does HTML in the data get rendered?
A No. Both v-text and {{ }} escape HTML; tags show literally — the built-in XSS protection.
Q When should I use it instead of interpolation?
A Use it when the element holds exactly one piece of text and nothing else, for shorter markup.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏