This repository has been archived on 2021-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
vuejs_course/2021-05-05_vuex-11-a-challe.../src/store/modules/cart/getters.js

22 lines
436 B
JavaScript

export default {
quantity(state) {
var itemsInCart = 0;
state.items.forEach(item => {
itemsInCart = itemsInCart + item.qty;
});
return itemsInCart;
},
items(state) {
return state.items;
},
total(state) {
var total = 0;
state.items.forEach(item => {
var itemTotal = 0;
itemTotal = item.price * item.qty;
total = total + itemTotal;
});
return total.toFixed(2);
}
};