Events

Events are used in two ways — the recipient that subscribes to an event and the emitter that fires it, very much like Angular's concept of output and EventEmitter.

To subscribe to an event, you use the at sign (@) — @event="expr". On the left side of the equation, the event corresponds to the event name, while the expression on the right specifies what to execute, usually a certain method.

On the other end, when a child component needs to trigger an event, you use a function provided to you by Vue called $emit, passing it the event name and relevant payload if needed, as shown in the following example:

this.$emit('click', 'some payload');

To demonstrate events, let's change the Parent component to subscribe to an update event fired ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.