vuetify文件上传 file inputs

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>

js

1.

// 上传文件方法
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'
    }
  })
}

2

 // 上传文件方法
uploadFile(value) {
  // console.log(this.fileInfo, '文件信息');
  if (this.$refs.uploadFileForm.validate()) {
     
    // this.loading.uploadIsLoading = true;
    var formData = new window.FormData();
    formData.append('file', value);
    debugger
    this.collectorImport(formData) 
  }
},
//collectorImport 是封装的ajax方法,不管用什么ajax请求方法,主要是设置请求头'Content-Type': 'multipart/form-data'
collectorImport(data){ 
  const ths = this;
        httpDefaultMsgUtil.post(
          "api/Management/Upload",
          data,
          {'Content-Type': 'multipart/form-data'},
          ths,
          (sucess) => {  
            //
            alert(sucess.data.message);
            const ths = this;
    const fieldsSetting = ths.gridLayoutFieldSettingArray;
    const getFieldObjFn = gridLayoutUtil.getGridLayoutFieldSettingForFieldObj;
    const fieldObj = getFieldObjFn(fieldsSetting, "头像");
    fieldObj.value="http://localhost:21021/uploads/images/1.jpg";
          }
        );
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

香煎三文鱼

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值