1

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?

1

2 Answers 2

2

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)
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

@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)
     }

4 Comments

Thanks a lot for your answer! I realized I need to put one parameter in event-handler like your answer.
Thank you so much!
you're welcome, @change="getFileObject($event)" allows you to pass other parameters if you want, and files:File[] enforces the typing
I wanted to write like TypeScript to enforce the typing, but I didn't have any ideas to file object. I really understand. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.