Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what situations would one choose v-text over the "mustache" syntax?

Tags:

vue.js

vuejs2

According to the VueJS docs, <span v-text="msg"></span> is the same as <span>{{msg}}</span>. Out of really nothing other than habit I always use the "mustache" syntax to bind data. In what situations would one choose to use v-text instead, and why?

like image 375
MattDionis Avatar asked Jun 29 '17 00:06

MattDionis


People also ask

What is v text in Vue?

The v-text directive is a Vue. js directive used to update a element's textContent with our data. It is just a nice alternative to Mustache syntax. First, we will create a div element with id as app and let's apply the v-text directive to this element with data as a message.

Which data binding interpolation is also known as Mustache syntax?

Text. The most basic version is using double curly braces, commonly known as the mustache syntax. This would create a one-way data binding from the model to the template.

What is the main usage of Vue JS?

VueJS is primarily used to build web interfaces and one-page applications. In saying that, it can also be applied to both desktop and mobile app development thanks to the HTML extensions and JS base working in tandem with an Electron framework – making it a heavily favoured frontend tool.

Why is VUE js called a progressive framework?

Vue. js is called a progressive framework because it is being changed and developed continually. Vue. js is called a progressive framework because it facilitates us to create Dynamic User Interfaces and single-page applications.


2 Answers

One reason you might want to use v-text is if you need to pre-render some markup on the server, but also have it bind client-side. For example:

<span v-text="msg">This message was pre-rendered from the server.</span>

That way the {{msg}} syntax doesn't get in the way of the content.

like image 112
CJW Avatar answered Sep 27 '22 16:09

CJW


This directive updates a html-node with innerContent. Html will not be rendered like with v-html. You can use v-text to have your template look other but internally, {{ Mustache }} interpolations are also compiled as a v-text direcitve.

like image 36
Reiner Avatar answered Sep 27 '22 17:09

Reiner