Two-way binding with v-model
In the previous section, we learned how our form should be defined, and it is now time to put this learning into practice by enhancing our Companion App with a couple of forms. In this section, we will learn how to use v-model
to enable our input field to accomplish two-way binding, which is a term used to describe when a field can emit change events and update values simultaneously (hence two-way).
In the previous chapter, we mentioned that the solution used to manage the value in the CreatePost
component was suboptimal, and it is now time to align it to use the best industry standards.
Let’s start by rephrasing what two-way binding really achieves. Let’s consider an input field, for example. Until now, we have learned how to set the value of this field using ref
. The use of ref
allows us to set the value of a specific input field at load, but this is not very useful when it comes to forms, as we want the value to be set by the visitor...