-2

I have a loop and I have 4 inputs in this loop. I want to give the id values from each loop separately to my 4 inputs, how do I do that? enter image description here enter image description here

i am running a loop there is only one input this input is values ​​from a loop how do i provide value retention for each individual using a v-model

2 Answers2

1

This is basic Vuejs. You need to return data as follows:

<script>
export default {
  data() {
    return {
      items: [{ message: 'Foo' }, { message: 'Bar' }]
    }
  }
}
</script>

Then you create a v-for loop:

<template>
  <div v-for="(item, index) in items">
        <input :id="index" v-model="item.message" />
  </div>
</template>

So in your case it might looks something like:

<script>
  export default {
    props: {
      altinFiyati: Object
    },
    data() {
      return {
        altinCount: this.altinFiyati,
      }
    }
  }
</script>

Then in your v-for loop you would connect whatever data to your v-model input:

<template>
  <div v-for="(item, index) in altinCount">
        <input :id="index" v-model="item.message" />
  </div>
</template>
Anthony Bird
  • 200
  • 2
  • 7
  • Hello, When I enter data into the input, the data I entered and the current sales price of gold should multiply with the input and the data I entered, but since I have only one input, the input is required. I don't know how to configure – Serkan Hakverdi Jan 11 '23 at 12:08
  • This would have to be calculated with function that you would use. You need to share your code to get better help. – Anthony Bird Jan 11 '23 at 12:14
0

What went wrong? Is your component properly configured to use v-model? Additionally, since you are presently iterating over that item, you do not need to pass in listOfItems[index]. Instead, you may just refer to the item with the v-model="item" prefix.

  • Hello. When I enter data into the input, the data I entered and the current sales price of gold should multiply with the input and the data I entered, but since I have only one input, the input is required. I don't know how to configure – Serkan Hakverdi Jan 11 '23 at 12:08
  • Instead of simply providing the answer directly, try writing a detailed comment that explains the solution, as long as the explanation is not too lengthy. @ric.jacqueline – DSDmark Jan 12 '23 at 15:53