Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
pass value to <input> after every for loop in methods

I'm working with BootstrapVue.

I have a for loop where I get unique numbers of a array these are named this.number - I input.push() my b-form-input (in this example) 3 times.

Every time I'm inputing a new b-form-input I want to pass the first and then of course my next number of this.number to my input that it will be shown there.

How can I do that? Thank You!

template:

<div v-for="(id, index) in inputs" :key="index">
  <b-form-input type="number" v-model="id.number" :value="id.number" @input="searchNumber(id, index)" ></b-form-input>
</div>

my script:

methods: {
  inputValue() {
    for (let i = 0; i < 3; i++) {
      this.number= (String(this.data[i].number));
      this.inputs.push({});

      console.log(this.number);
    }
  }
},

data() {
  return {
    inputs: [{}],
  }
},

my console.log(this.number)

1111
2222
3333

So 1111 should be v-model/value of b-form-input 0, 2222 should be v-model/value of b-form-input 1 and 3333 should be v-model/value of b-form-input 2

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

From what I understood what you are trying to do is:

  1. Render 3 inputs
  2. When user inputs in input number 2 it updates the input number 2

You have your code organized in a way that is difficult to follow what is going on. My suggestion is to have a function that is triggered when an input emits a input event and then pass the index (almost what you have with searchNumber)

<div v-for="(id, index) in inputs" :key="index">
  <b-form-input type="number" :value="id.number" @input="onInput($event, index)" ></b-form-input>
</div>
methods: {
  onInput(input, index) {
    this.inputs[index].number = input;
  }
}

Note that I have removed v-model from your b-form-input. Now we only have value and @input.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda