0

it turns out that I want to perform some operations, but as much as I try I get errors, I hope they can help me. they wanted to perform some operations with 4 inputs

Example

these conditions must be met

         `Input 1     Input 2     Input 3    Input 4

               1) input3 = input1 / input 2
                   2) input2 = input1 * input 3
                       3) input2 = input 4`

currently is what I have

calcularPrecio: function(){
                var result=0.0;
                
                for(var i=0;i<this.arrayDetalle.length;i++){
                 result=result(this.arrayDetalle[i].precio*this.arrayDetalle[i].cantidad1)
                }
                return result;
            },
<input type="number"  v-model="calcularPrecio"  class="form-control">

<input v-model="detalle.cantidad1" type="number" class="form-control">

I hope you could help me with an example of how I could do it. Thank you so much

4
  • Are you trying to check if the value of Input1/Input2 equals to Input3? Can you please provide javascript code that you are using! Commented Aug 1, 2020 at 4:25
  • what I require is that the values ​​are dependent Commented Aug 1, 2020 at 4:27
  • It doesn't make sense that input2 is dependent on input4 and input1 * input3, if you're looking to use computed functions. Unless you want the input returned separately, for which input2 would be two different computed properties. Commented Aug 1, 2020 at 4:30
  • yes exactly that's what I require 2 functions for input 2 Commented Aug 1, 2020 at 4:32

1 Answer 1

1

You could do this with simple functions:

methods: {

   calcA: function () {
       this.inputC = this.inputA / this.inputB

   },
   calcBA: function () {
       this.inputB = this.inputA * this.inputC

   },
   calcBB: function () {
       this.inputB = this.inputD

   },
}

or you could use computed properties:

computed: {
   outputA: function () {
       return this.inputA / this.inputB

   },
   outputB: function () {
       return this.inputA * this.inputC

   },
   outputC: function () {
       return this.inputD

   },
}

You could also use params for the methods, if that's what you want.

There's a 3rd option where you use watchers to watch input4 for example. On change, update input2.

Sign up to request clarification or add additional context in comments.

1 Comment

and the result of the outputs as the subjects to the inputs?

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.