Using the $event parameter
Vue.js provides access to the Event
object associated with the event. This object can then be used to get additional information about the event. The information is different depending on the type of event:
- Mouse coordinates or buttons clicked on the mouse for a mouse-related event
- Keyboard key used, or the combination of keys pressed (Ctrl, Shift, Esc, and so on) for a keyboard-related event
The Event
object can be accessed from the $event
variable. It can be passed as a parameter to a processing method. This parameter will then be retrieved in the event processing function.
Let’s see two examples of how to use this parameter when entering characters in an edit control:
- By displaying an error message as soon as the numerical value entered equals or exceeds the value 100
- By prohibiting the entry of characters other than numeric characters if the edit control can only contain numbers (this is an improvement of the previous...