A
A
asferot2018-12-27 13:26:34
Vue.js
asferot, 2018-12-27 13:26:34

How to calculate the amount?

How can I calculate the total sum of elements?
This is the array to which the elements will be added. item.price - the price of one item and I need to add it to the rest of the items outside this array

tr(v-for="(item, index) in cartItems" v-show="numCartItems != 0" )
                td 1
                td(class="width-img-td")
                    img(:src="item.img" class="imgs")
                td(v-model="took_item") {{ item.title }}
                td(v-show="numCartItems != 0" ) {{ numCartItems }}
                td шт
                td {{ item.price }}

I need to add item.price to other items
data:{
      encoder: 25000,
      cardData: 2500,
      mifare: 120,
      programmator: 58000
}

computed: {
    total(){
            var b = this.encoder;
            var c = this.cardData;
            var d = this.mifare;
            var e = this.programmator;
            return item.price + b + c + d + e;
        }
      }
    },
}

tr
     td(colspan="7" class="right -bold") Итого за оборудование:
     td {{total}} &#8381

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-12-27
@asferot

Change the computed property total
item.price
to (cartItems is an array, right?)

this.cartItems.reduce((sum, n) => sum + n.price, 0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question