Modifiers are incredibly useful tools for quickly adding essential front-end logic to directives. Vue offers modifiers for many of their directives, including the main topic of this lesson:
v-model. Yes, that’s right, we can use modifiers to make our form fields even more versatile.
Vue offers the following three modifiers for
.number— automatically converts the value in the form field to a number
.trim— removes whitespace from the beginning and ends of the form field value
.lazy— only updates data values when
changeevents are triggered (often when a user moves away from the form field rather than after every keystroke)
You can find out more information about these modifiers in the Vue documentation.
Let’s use modifiers to clean up some of the data in our form.
First, let’s use the
.trim modifier to remove any potential whitespace from our text fields. Add
.trim to the following form fields:
- The “First Name”
- The “Last Name”
- The “Email”
- The “Special Requests”
Next, let’s use the
.number modifier to ensure all of our number fields are stored as the correct data type.
.number modifier to the “Ticket Quantity”