1
votes

I have used Vuetify.js as Nuxt.Js's UI framework. I wanted to get file object when I input file my apps. So I used v-file-input component in Vuetify.Js and I made code like below.

    <template>
    <div>
        <v-file-input
            label="fileinput"
            multiple
            v-model="files"
            @change="getFileObject()"></v-file-input>    
    </div>    
</template>
<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'

@Component({})
export default class extends Vue{
    files:any = []
    fileObj:any = {}
    async getFileObject(file:any){
        this.fileObj = await file
        console.log(this.fileObj)
    }
}
</script>

I checked the file object using console.log. but 'this.fileObj' is undefined. How do I get file object when I input files? Could anyone advise me?

2

2 Answers

2
votes

If you remove the empty argument from the handler, it should be passed implicitly. It should also be on this.files which is used as the input's v-model:

@change="getFileObject"
methods: {
  getFileObject(file:any) {
    console.log(file);
    console.log(this.files)
  }
}
1
votes

@change event has one parameter which the files array :

  @change="getFileObject($event)"></v-file-input>   

then in script:

     async getFileObject(files:File[]){
         this.fileObj = await files
        console.log(this.fileObj)
     }