D
D
Dmitry2021-05-08 13:21:52
Arrays
Dmitry, 2021-05-08 13:21:52

How to calculate the sum of goods in vue.js?

Good afternoon, forum users, please help a newbie, I'm studying vue.js and the task was to calculate the sum of all goods, tell me how to implement this?

let cartBox = new Vue({
  el: '.marget',
  data: {
    cart: [
      {price: 1000, cnt: 2},
      {price: 800, cnt: 3}
    ]
  },
  computed: {
  cartTotal() {
      return this.cart.reduce((price, cnt) => price += cnt, 0)
    }
  }
});


I need 1000 times 2 and 800 times 3 and add it all up. how to do it? Tell me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-05-08
@teplyashin

price += cnt.cnt * cnt.price

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question