DEV Community

Discussion on: How to Vue - Props vs Data

Collapse
 
akwetey profile image
Jonathan Akwetey

is it possible to do a two way binding by using v-model to get dynamic props values?
I mostly do that for data.

Collapse
 
stikoo profile image
Alastair Hodgson

Yo Jonathan, v-modal is indeed used for two way binding, just not between parent-child components. You would use v-model to bind a components data to form inputs within the components

Collapse
 
proticm profile image
Milos Protic

If I understand the question correctly, I think that this should not be done in the first place.

Two way binding is exactly what its name says. A binding that goes in two directions. A property value comes from the parent data, so if you bind to it, since it is a two way binding, while changing the bound input value you are actually trying to mutate the parent data variable which, as said in this post is done with events ($emit option).

You are able to do this for data variables because, I assume, you have the data object defined on the component as a local state.

Collapse
 
akwetey profile image
Jonathan Akwetey

yeah you assumed correctly