Vue.js

[Vue.js] Categorizing lists

brightlightkim 2022. 5. 11. 08:39
//HTML
{{item.product.price | currency}}

methods: {
    addItem: function(product) {
        var whichProduct;
        var existing = this.cart.filter(function(item, index) {
            if (item.product.id == Number(product.id)) {
                whichProduct = index;
                return true;
            } else {
                return false;
            }
        });
        if (existing.length) {
            this.cart[whichProduct].qty++;
        }	else {
            this.cart.push({product: product, qty: 1})
        }
    }
}

'Vue.js' 카테고리의 다른 글

[Vue.js] Deleting Items and Modifiers  (0) 2022.05.11
[Vue.js] Adding computed classes  (0) 2022.05.11
[Vue.js] Toggling elements with a key  (0) 2022.05.11
[Vue.js] filters  (0) 2022.05.11
[Vue.js] Buefy, Vuetify  (0) 2022.05.11