Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
Obtenga valor en v-for loop en métodos en 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>

En métodos:

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

Estoy cargando una imagen en vuejs. Y quiero obtener el valor de index del bucle v-for bajo el handleClickUpload de los métodos. ¿Hay alguna forma de obtener index en handleClickUpload ? Por favor dame ideas. Gracias.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Prueba esto:

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

0

Puede pasarle una función y pasar el event y el index externamente como:

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

Demo en vivo

Demostración de Codesandbox

y obtenga el índice en la función handleClickUpload como:

 handleClickUpload(e, i) { console.log(e.target.files); console.log(i); },
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!