javascript / beginner
Snippet
Rendering Raw HTML with v-html
While Vue escapes HTML by default to prevent XSS attacks, v-html allows you to render raw HTML strings. Use this only for content you trust completely.
snippet.js
1
2
3
4
5
6
7
<template><div v-html="trustedHtmlContent"></div></template><script setup>const trustedHtmlContent = '<span style="color: red">Important!</span>';</script>
vue
Breakdown
1
v-html="trustedHtmlContent"
Updates the element's innerHTML with the provided string value.