r-text Directive
r-text binds an expression to an element’s textContent.
It is the safest and most direct way to render text output.
Syntax
Section titled “Syntax”<p r-text="expression"></p>Basic Example
Section titled “Basic Example”<p r-text="message"></p>When message changes, the element text updates reactively.
Expression Example
Section titled “Expression Example”<p r-text="user.firstName + ' ' + user.lastName"></p>r-text vs {{ ... }}
Section titled “r-text vs {{ ... }}”Both are valid. Prefer r-text when:
- You want explicit binding at element level.
- You are optimizing repeated row templates and want predictable binding points.
- You want to avoid accidental surrounding whitespace behavior from text nodes.
Security and Behavior
Section titled “Security and Behavior”r-textwrites plain text, not HTML.- HTML tags in values are escaped as text.
- Use
r-htmlonly when you intentionally need HTML rendering.
Common Patterns
Section titled “Common Patterns”<li r-for="row in rows" :key="row.id"> <span r-text="row.id"></span> <span r-text="row.label"></span></li>This is a clear and performant default for list text output.