From the course: Vue.js 3 Essential Training
Unlock this course with a free trial
Join today to access over 24,000 courses taught by industry experts.
Component events
From the course: Vue.js 3 Essential Training
Component events
- [Instructor] When you create an event inside a component, it can trigger something in the parent, and it's also going to pass along some information. Let's take a look at how that works. So the effects of the component can be passed along to the parent using a method called emit. Now, you add this in the child template, and then you can use a regular JavaScript event like a click. So this event can be anything here, this could be a click or any other type of JavaScript event, and that would trigger a custom event that we're calling here at myEvent, and optionally, you can pass along a value. Here's what it looks like when you call it in the parent component. So this is what you do in the template, and then this happens in the parent. You actually call that event just like you would a click event or any other event, but this isn't the component call, and then you can do something when that event takes place. That means…