0

I am getting this error when I am trying to load image in vue using vuetify.

Error: TypeError: Cannot read property 'files' of undefined"

The component:

<v-file-input
          accept="image/*"
          label="File input"
          @change="uploadData($event)"
        ></v-file-input>

The method:

 methods: {
    uploadData(event) {
      let file = event.target.files[0];
      console.log(file);
    }
}

1 Answer 1

1

The @change has files array as parameter by default, no need to specify the $event parameter :

<div id="app">
  <v-app id="inspire">
    <v-file-input
      accept="image/*"
      label="File input"
       @change="uploadData"       
    ></v-file-input>
  </v-app>
</div>
new Vue({
  el: '#app',
  vuetify: new Vuetify(),
   methods: {
    uploadData(files) {
   console.log(files)
    }
}
})

LIVE DEMO

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.