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

209
Visualizações
Vue put focus on an input via refs

I use v-for to create inputs foreach item in a list, i assign a ref in the following way

:ref="`input-${index}`"

which makes my $refs look like this

enter image description here

Now my question is; on the addition of an input I also want to put focus on the last input, however I can't manage to make it work.

Right now I tried something like this,

this.$refs["input-" + index.toString()].focus()

however I feel like it has to do with the structure of refs I don't know how to deal with.

Does anybody know how I can access each input and how to focus it (i guess just .focus()).

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

0

It seems that you're using ref inside a v-for loop, in this case is recommended to use the ref in the root element containing the v-for directive as follows :

 <input v-for="(item, index) in items" ref="inputs" .../>

this will create an array of the referenced elements that you could use them like :

 this.$refs.inputs[someIndex].focus()

or

 this.$refs.inputs[this.$refs.inputs.length-1].focus() // focus on the last input
about 4 years ago · Juan Pablo Isaza Relatório

0

So I do not know exactly anymore, however I remember that the problem was that I was putting focus on the ion-item rather than the ion-input. I needed to add .children[i] (i depending on what child it is). this allowed me to put focus in the 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