[Vuejs]-How to get the v-model of component that called the function in Vuetify?

1👍

Using an array to hold all the values of your inputs and passing the array index to the event handler method is the most common way of solving your problem. With an array you can also utilize v-for to dynamically render your input elements, which cuts down on duplicate code.

<template>
  <v-app>
    <v-text-field 
      v-for="(foo, i) in foos" :key="i" 
      type="number"
      v-model.number="foos[i]"
      @input="updateForm(i)"
    />
  </v-app>
</template>
<script>
export default {
  data() {
    return {
      foos: [0, 0]
    };
  },

  methods: {
    updateForm(fooIndex) {
      this.foos[fooIndex] += 1;
    }
  }
};
</script>

👤yoduh

Leave a comment