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

291
Visualizações
Get value in v-for loop into methods in vuejs
<form method="post" action="#" enctype="multipart/form-data">
<div class="row">
    <div class="col-md-12">
       <div class="image-upload" v-for="(item, index) in uploadVal" :key="item._id">
          <label class="btn btn-sm btn-success">
              <a-icon type="upload" />Upload
              <input
                type="file"
                ref="file"
                accept="image/*"
                @change="handleClickUpload"
                style="display: none;"
              />
        </label>
        <div class="show-img">
            <img :src="getImageURL(item.url)" />
        </div>
       </div>
    </div>
</div>
</form>

In methods:

methods: {
   handleClickUpload(e) {
      console.log(e.target.files);
   },
}

I am doing upload image in vuejs. And I want to get the index value of the v-for loop under the handleClickUpload of the methods. Is there any way to get index in handleClickUpload ? Please give me ideas.Thanks

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Try this:

@change="handleClickUpload($event, index)"
methods: {
  handleClickUpload(e, i) {
    console.log(e.target.files, i);
  },
}
over 4 years ago · Santiago Trujillo Relatório

0

You can pass a function to it and pass the event and index externally as:

<input
  type="file"
  ref="file"
  accept="image/*"
  @change="(e) => handleClickUpload(e, index)"
  style="display: none"
/>

Live Demo

Codesandbox Demo

and get the index in the function handleClickUpload as:

handleClickUpload(e, i) {
  console.log(e.target.files);
  console.log(i);
},
over 4 years ago · Santiago Trujillo 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