R
R
r_g_b_a2020-02-21 09:19:18
Vue.js
r_g_b_a, 2020-02-21 09:19:18

How to use results with computed in data in vue?

Hello. I have this simplified example: https://jsfiddle.net/8d6khn0L/
The calc function calculates the area and perimeter based on user input. I need to use these values ​​to calculate the markup when selecting options. For example, when selecting the first checkbox, multiply its price value with the calculated area and display it in {{option.margin}} . How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-02-21
@r_g_b_a

Add a property to the options that will indicate what price should be multiplied by:

options: [
  {
    ...
    propToBeMultipliedByPrice: 'area',
  },
  {
    ...
    propToBeMultipliedByPrice: 'perimeter',
  },
],

And multiply:
{{ option.price * calc[option.propToBeMultipliedByPrice] }}

V
Vladimir Korotenko, 2020-02-21
@firedragon

What's in {{}} is a java script so you can write any expression.
Although it's better to add 2 method calculateMargin and call it instead of date

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question