Reputation: 416
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);
}
}
Upvotes: 0
Views: 215
Reputation: 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)
}
}
})
Upvotes: 1