vuetify文件上传 file inputs

本文介绍了如何利用Vuetify组件库在HTML和JavaScript中实现文件上传功能,包括相关的HTML结构和JavaScript处理逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. html部分代码
<v-form
       ref="uploadFileForm"
       v-model="uploadFormValid">
   <v-file-input
           v-model="fileInfo"
           required
           :rules="[v => !!v || '文件必选']"
           show-size accept=".xls,.xlsx"
           @change="uploadFile"
           :disabled="loading.uploadIsLoading"
           :loading="loading.uploadIsLoading"
           label="点击选择文件,文件格后缀为:.xls、.xlsx"></v-file-input>
</v-form>
  1. js部分
// 上传文件方法
uploadFile() {
  // console.log(this.fileInfo, '文件信息');
  if (this.$refs.uploadFileForm.validate()) {
    this.loading.uploadIsLoading = true;
    var formData = new window.FormData();
    formData.append('file', this.fileInfo);
    collectorImport(formData).then(res => {
      this.loading.uploadIsLoading = false;
      this.$refs.notify.show("文件上传成功", {timeout: 1000, color: 'success'});
      this.uploadDialog = false;
      this.search();
    }).catch(err => {
      this.loading.uploadIsLoading = false;
    });
  }
},
//collectorImport 是封装的ajax方法,不管用什么ajax请求方法,主要是设置请求头'Content-Type': 'multipart/form-data'
collectorImport(data){
  return request({
    url:'/db/collector/collector-import',
    method:'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值