简体   繁体   中英

How to get file object using v-file-input in Nuxt.js?

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM