Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between v-html and v-text?

I had the following code using v-text:

<h1 v-text="content.title"></h1>

Output:

Brand Name is B&amp;C

So I fixed it using v-html in the previous line:

<h1 v-html="content.title"></h1>

Output:

Brand Name is B&C

My question is the following:

Why does it works using v-html and not v-text? I already read the Vue documentation but I don't clearly understand the difference.

like image 787
Ced Avatar asked Nov 15 '18 13:11

Ced


People also ask

Should I use V-HTML?

Dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to XSS attacks. Only use v-html on trusted content and never on user-provided content.

What is v-model in HTML?

The v-model is a two-way binding which means if you change the input value, the bound data will be changed. The v-model directive is used to create two-way data bindings on form input, textarea, and select elements. Example: HTML.

What is the difference between V if and V show?

The key difference is that v-if conditionally renders elements and v-show conditionally displayselements. This means that v-if will actually destroy and recreate elements when the conditional is toggled. Meanwhile, v-show will always keep the element in the DOM and will only toggle its display by changing its CSS.

What is Vue HTML?

Vue.js lets you extend HTML with HTML attributes called directives. Vue.js directives offers functionality to HTML applications. Vue.js provides built-in directives and user defined directives.


1 Answers

v-text sets the textContent of the node. v-html sets the innerHTML of the element. &amp; is an HTML entity. If you want HTML entities interpreted and replaced, you need to have them interpreted as HTML and not text.

like image 113
Roy J Avatar answered Nov 15 '22 10:11

Roy J