[Vuejs]-Dynamic input value related to another values

0👍

Add an on change event to the duration:

<input class="form-control" id="inputDuration" min="4" step="4" type="number" v-model="newTask.duration" onchange="myFunction()">

Then write some JavaScript which gets the value of the duration on change and updates the workload value based on that.

<script>
function myFunction() {
  var inputDurationValue = document.getElementById("inputDuration").value;
  document.getElementById("inputWorkload") = inputDurationValue;
}
</script>

-1👍

With a watcher. Something like this.

data: {
    //define your #inputWorkload variable , let's say "workload"
},

watch: {
    newTask: {
        handler(val){
            this.workload = val.duration * 2;
       },
       deep: true
    },
 }
// in your template

<input disabled class="form-control" id="inputWorkload"  :value="workload">

Leave a comment