为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 Nuxt.js 中使用 v-file-input 获取文件对象?

如何在 Nuxt.js 中使用 v-file-input 获取文件对象?

繁星点点滴滴 2023-10-20 10:29:21
我使用 Vuetify.js 作为 Nuxt.Js 的 UI 框架。我想在输入文件我的应用程序时获取文件对象。所以我在 Vuetify.Js 中使用了 v-file-input 组件,并编写了如下代码。    <template>    <div>        <v-file-input            label="fileinput"            multiple            v-model="files"            @change="getFileObject()"></v-file-input>        </div>    </template><script>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>我使用 console.log 检查了文件对象。但“this.fileObj”未定义。输入文件时如何获取文件对象?有人能给我建议吗?
查看完整描述

2 回答

?
慕婉清6462132

TA贡献1804条经验 获得超2个赞

如果从处理程序中删除空参数,则应隐式传递该参数。它还应该在this.files用作输入的v-model:


@change="getFileObject"

methods: {

  getFileObject(file:any) {

    console.log(file);

    console.log(this.files)

  }

}


查看完整回答
反对 回复 2023-10-20
?
扬帆大鱼

TA贡献1799条经验 获得超9个赞

事件有一个参数,该参数是文件数组:


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

然后在脚本中:


     async getFileObject(files:File[]){

         this.fileObj = await files

        console.log(this.fileObj)

     }


查看完整回答
反对 回复 2023-10-20
  • 2 回答
  • 0 关注
  • 75 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信