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

Vue 3 v-html Directive

Vue 3 v-html Directive

Vue3 Built-in Directives Vue 3 Built-in Directives


v-html The directive is used to update the element's innerHTML, rendering content as raw HTML.


Basic Explanation

v-html The directive inserts the value of its bound expression into the element as HTML. This is useful when you need to render rich text content.


Use Cases

1. Render Rich Text Content

When fetching HTML content from the server and needing to render it:

Example


Security Warning

Security Issue: Dynamically rendering arbitrary HTML may lead to XSS (Cross-Site Scripting) attacks. Always ensure v-html content is trusted; never use v-html on user-submitted content.


Difference from v-text

Instruction Purpose Example
v-text renders content as plain text v-text="'testdisplays test
v-html parses content as HTML v-html="'testdisplays test (bold)

Vue3 Built-in Directives Vue 3 Built-in Directives