Directives v-text & v-html & v-pre

v-text

This directive accepts as an argument a variable representing the text with which the entire content of the tag should be updated. It has the same functionality as string interpolation.

See the Pen v-text by Web programming (@chos) on CodePen.


vue.js

v-html

By using this directive, we enable content to be inserted as plain HTML, ie. Vue.js will not process it as if it were a template compiler. The problem can occur with “single-file component“, because the styles from the component will not affect the content inserted with this directive.

When to use the v-html directive?

Dynamic rendering of arbitrary HTML can be very dangerous, as it can easily lead to XSS attacks. It is recommended that the “v-html” directive be used only for trusted content, which implies that it should never be used for user-input content. One reason to use this directive is to inject unicode code (eg 😸 HTML processed and generated in 😸)

Example

See the Pen v-text by Web programming (@chos) on CodePen.

v-before

The content of the HTML tag containing the “v-pre” directive will not be processed and compiled by Vue.js, but will be displayed exactly as written in the code itself.

Example

On an element that has the directive “v-pre” no interpolation will be performed, but double brackets will be displayed.

See the Pen V-pre by Web programming (@chos) on CodePen.