0

All of the properties I add have a value, but there is still something that is not correct. I am trying to calculate the grand total by multiplying the price by the number of purchases, which is iterated through an array.

total () {
      return this.items.reduce((total, item) => {
        return total + item.qty * item.price
      }, 0)
    }

I try to change to composite api 118:12 error Parsing error: Missing semicolon. (48:12)

    total () {
      return items.reduce((total, item) => {
        return total + item.qty.value * item.price.value
      }, 0)
    }

2
  • The snippets lack the context. See stackoverflow.com/help/how-to-ask and stackoverflow.com/help/mcve . There's no methods object in composition api, so it's unclear why total () property is intact Commented Nov 29, 2022 at 21:49
  • const total = promos.value.reduce((total, promo) => { return total + promo.numboos.value * promo.price.$numberDecimal.value }, 0) The error is gone but total always 0 how can I fix Commented Nov 30, 2022 at 0:24

1 Answer 1

1

try this code

 const total = computed(() => {
      return items.value.reduce((total, item) => {
        return total + item.qty * item.price
      }, 0)
    })
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.