Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between 1-way binding and 2-way binding in Vue js?

Tags:

vuejs2

Could anyone explain the difference between One-way binding and Two-way binding in Vue js with an example each, and explain which situation to be used?

like image 597
Darshan theerth Avatar asked Oct 15 '25 12:10

Darshan theerth


1 Answers

One-way binding is updating the DOM from the data (ViewModel). Always when the data (ViewModel) changes, the associated node (element) is re-rendered:

<span>Message: {{ msg }}</span>

With the v-once directive, the whole binding is only done once - even when the data changes.

Two-way binding is updating the DOM from the data (ViewModel) and updating the data (ViewModel) on events from the node (element). Normally input fields are Two-way binding to reflect changes from the user back to the data:

<input v-model="message" placeholder="edit me">
<p>Message is: {{ message }}</p>

Please read the documentation.

like image 190
CodeTherapist Avatar answered Oct 18 '25 08:10

CodeTherapist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!