From the course: Vue.js 2 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Emitting events from within components

Emitting events from within components

From the course: Vue.js 2 Essential Training

Start my 1-month free trial

Emitting events from within components

- [Instructor] And the sub-component that we created, where we are listing the products, we're actually already managing some local events in the JavaScript. If we-- Let's go ahead and close the price component. In this product list component, we have a series of methods here. And the methods are actually referring to events that are handled locally. Before enter, enter and leave, are methods that are being used by our transition group, and they're right here. So this is how you take care of working with events inside a component, just like you would inside the main view object. But what if we want this component to send something to its parent component? And where we're going to do that is by hitting this plus sign, we want to add an item into the cart. To do that, it requires a slightly different notation, and it's actually pretty easy. So that is handled by emitting an event from this component, and then catching it in the previous component. So it's going to essentially allow this…

Contents