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.

Events and methods

Events and methods

From the course: Vue.js 2 Essential Training

Start my 1-month free trial

Events and methods

- [Instructor] Let's take a look at how events work in Vue.js. To show you, I have added these buttons right here at the beginning of each one of the products. If we scroll down here, we should be able to see this button right here with a plus sign and it's got a couple of Bootstrap classes so that they look nice. In addition to that, I've created this nav bar. Let me show you where that is, it's right up here. This nav bar is going to allow me to place the number of cart items that I have and it's a nav, so it stays up at the top because I have this fixed-top class right here from Bootstrap. Let's start first by, in our data, we are going to add another reactive property here, 'cause remember if we don't define it then it's not going to be a reactive. I'm going to call this cart and I'll initialize it with an empty array. Then, in order to take care of an event, what I'll do is find the button and then in this button, I want to use the v-on and this is how we do events. Then I want…

Contents