Challenge - 5 Problems
v-html Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this Vue component render?
Consider this Vue 3 component using
v-html. What will be the visible output in the browser?Vue
<template> <div v-html="rawHtml"></div> </template> <script setup> import { ref } from 'vue' const rawHtml = ref('<p><strong>Hello</strong> <em>World</em>!</p>') </script>
Attempts:
2 left
💡 Hint
Remember that
v-html renders the string as HTML, not plain text.✗ Incorrect
The v-html directive tells Vue to insert the string as raw HTML inside the element. So the tags like <strong> and <em> are interpreted by the browser, showing bold and italic text respectively.
📝 Syntax
intermediate1:30remaining
Which option correctly binds raw HTML using v-html?
You want to display raw HTML stored in a Vue ref called
content. Which of these is the correct syntax?Attempts:
2 left
💡 Hint
v-html is a directive and expects a JavaScript expression without mustache syntax.✗ Incorrect
The correct way to bind raw HTML is v-html="content". Using mustache syntax inside v-html or prefixing with a colon is incorrect.
🔧 Debug
advanced2:30remaining
Why does this v-html binding not update when the data changes?
Given this Vue 3 component, why does the displayed HTML not update when
rawHtml changes?Vue
<template> <div v-html="rawHtml"></div> <button @click="changeHtml">Change HTML</button> </template> <script setup> import { ref } from 'vue' const rawHtml = ref('<p>Original</p>') function changeHtml() { rawHtml = '<p>Updated</p>' } </script>
Attempts:
2 left
💡 Hint
Remember how to update the value inside a ref in Vue 3.
✗ Incorrect
In Vue 3, refs are objects with a .value property. To update the reactive value, you must assign to rawHtml.value, not replace the ref variable itself.
🧠 Conceptual
advanced1:30remaining
What is a major security risk when using v-html with user input?
Why should you be cautious about using
v-html to render HTML content that comes from users?Attempts:
2 left
💡 Hint
Think about what happens if someone inserts a