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.

Adding computed classes

Adding computed classes

From the course: Vue.js 2 Essential Training

Start my 1-month free trial

Adding computed classes

- [Instructor] There's a little bit of a problem when we add more than one of the same items. Although the dropdown shows these elements properly, you can see that the elements aren't really adding up right here in this cart section. So, let's go ahead and fix that. We'll use some computed properties. I did notice that I need to add an additional class here of dropdown for things to be aligned properly. So now let's try adding some items here, and now the dropdown is a little bit better aligned with my menu item, but we still have to fix the other issue. So to do that, we are going to add some additional computed properties. I'll add one called cartTotal, and this'll be pretty simple. Let's go ahead and hide this for a second. And we'll do a variable here called sum, initialize it to zero, and it should be cartTotal. And then we'll create a loop for key in this.cart. So go through each of the elements in the cart and then calculate the sum of the elements. So we'll just use the…

Contents