Implementing `inc` and `dec` logic
Let's now implement the logic of these two methods. Firstly, inc
. We're passing in the item that the user wants to increment. So we can simply just go item.qty++
.
Keep in mind we also need to increment the total
value as well by the price of the item. We can do that by going this.total += item.price
like that.
methods: {
addItem: function(index) {...},
inc: function(item) {
item.qty++;
this.total += item.price;
},
dec: function(item) {...}
}
Click to load comments...