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

150
Views
VueJS3 + Typescript - Leer archivo desde el archivo de entrada

Quiero subir algún archivo, pero no puedo acceder con v-model

VueCompilerError: v-model no se puede usar en entradas de archivos ya que son de solo lectura. Utilice un oyente v-on:change en su lugar.

Entonces, cambié el v-model v a v-on:change código similar a continuación, pero no sé cómo hacerlo

 <input type="file" name="file" v-on:change="uploadFile" style="display: none; border: none" />

Leí una gran lista de ejemplos, pero ninguno funcionó.

Mis datos (no sé si es correcto) :

 data() { return { file: null as unknown as File, }; },
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Un ejemplo básico podría verse así

 <input type="file" @change="onFileChange">

versión de JavaScript

 methods: { onFileChange(e) { let files = e.target.files || e.dataTransfer.files; if (!files.length) return; doSomethingWithTheFile(files[0]); }, }

La versión de TypeScript podría verse así

 interface HTMLInputEvent extends Event { target: HTMLInputElement & EventTarget } methods: { onFileChange(event: HTMLInputEvent | DragEvent) { let files = (event as HTMLInputEvent).target.files || (event as DragEvent).dataTransfer.files if (!files.length) return doSomethingWithTheFile(files[0]) }, },
about 4 years ago · Juan Pablo Isaza Report

0

¿Cómo se ve tu uploadFile ?

Lo más simple puede ser declararlo para tomar directamente la lista de archivos:

 async uploadFiles(fileList: Array<File>) { for (const file of fileList) { // do something with the file

Y llámalo así:

 v-on:change="uploadFiles($event.target.files)"
about 4 years ago · Juan Pablo Isaza 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!