Anekdotin
Anekdotin

Reputation: 1591

Typescript property doesnt exist on type unknown with file uploader

I am trying to create an upload image vue component. I am getting multiple errors from webstorm and Ive tried copying and pasting similar code with the same error. I also get the error on using .click() . The error on hover states "Property files doesnt exist on type unknown"

enter image description here

Upvotes: 1

Views: 97

Answers (1)

Kadir Damene
Kadir Damene

Reputation: 358

use it like this:

const fileInput = this.$refs.fileInput1 as HTMLInputElement

if (fileInput?.files && fileInput.files[0]){
  formData.append('image_main', fileInput.files[0])
}

Upvotes: 1

Related Questions