Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative binding syntax in Vue.js

Tags:

Question

I want to know if there is an alternative syntax to output data in Vue.js, instead of the curly braces, like the ng-bind Angular directive.

Reading the docs, it seems that Vue.js accepts only tag properties with the v-bind directive, but I want it to work with the inner html too.

Context

I want to output data using PHP and, once the page is loaded, manage it with Vue. Imagine the next situation:

We want this output:

 <div>Hello</div> 

First, we output the data with php

 <div><?php echo $hello_string ?></div> 

After that, we want to be able to change the content with Vue. The current syntax is;

 <div>{{ hello_string }}</div> 

We can't mix the two syntaxes, so I need something like this:

&lt!--Ideal syntax for mixing vue and php--> <div v-bind:innerhtml="hello_string"><?php echo $hello_string ?></div> 

Thank you for your help.

like image 359
rogervila Avatar asked Dec 21 '15 21:12

rogervila


People also ask

What is two way binding in VUE JS?

The v-model directive makes two-way binding between a form input and app state very easy to implement. One can bind a form input element and make it change the Vue data property when the content of the field changes.

How can you bind styles in VUE JS?

Binding Styles Dynamically To this end, Vue provides us with the v-bind:style directive. On each click event, the v-bind:style directive increments and decrements the value of your fontSize variable. This attaches the value of fontSize to the CSS font-size property.

What is binding in VUE JS?

In a data binding process, whenever data is changed, it is reflected automatically by the elements bound to the data. The term data binding is also used in cases where an outer representation of data in an element changes, and the underlying data is automatically updated to reflect this change.

What is the text interpolation data binding syntax in VUE JS?

Interpolation is the insertion of something of a different nature into something else. In the Vue. js context, this is where you would use mustache syntax (double curly braces) to define an area where you can inject data into a component's HTML template.


1 Answers

You could use the v-text directive:

<div v-text="hello_string"></div> <!-- same as --> <div>{{ hello_string }}</div> 

or the v-html:

<div v-html="html"></div> <!-- same as --> <div>{{{ html }}}</div> 
like image 87
Pantelis Peslis Avatar answered Oct 20 '22 09:10

Pantelis Peslis