手动上传与清除

1.上传文件改变的属性 对应的 方法 手动上传文件  用submit

2.替换多少次,上传接口就要请求多少次,显得比较多余,浪费性能   清除多余用 clearFiles

   ----html
              <el-upload
                    class="avatar-upload"
                    ref="upload"
                    list-type="picture"
                    :file-list="fileList"
                    action="#"
                    v-model="file"
                    :auto-upload="false"
                    :http-request="uploadFile"
                    :on-success="uploadFile1"
                    :before-upload="beforeAvatarUpload"
                    :on-change="(file,fileList) => changeFile(file,fileList)"
                    :show-file-list="false"
                >
                    <btn-free style="margin-top: 0.7rem;" btnTxt="导入"/>
                </el-upload>

----js
          methods: {
        
             changeFile1(file,fileList,item,index){
                  this.file = fileList[fileList.length - 1]
                  console.log('this.file',this.file)
                  this.$refs.upload.submit();
            },
            changeFile(file,fileList){
                if(file.status=='ready'){
                     this.$prompt('请输入上传后的文件名', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        inputValue:file.name
                      }).then(({ value }) => {
                          this.file = fileList[fileList.length - 1]
                        //   this.fileName.name = value;
                          console.log('确定');
                        console.log('this.file',this.file);
                        console.log('value',value);
                        // this.$refs.upload.$children[0].post(file);;
                        this.$refs.upload.submit();
                      }).catch(() => {
                        console.log('取消');
                        this.$refs.upload.clearFiles();
                        this.$message({
                          type: 'info',
                          message: '取消文件上传'
                        });
                      });
                }
             },
        // 导入
    uploadFile(i1){
        let that = this
        let formData = new FormData()
        formData.append('file',that.file.raw); 

                          that.$uploader('/score/analyst/contact/importScoreAnalystContact',formData).then(res => {
            if(res.code == 1){
                that.getDataList()
                that.$refs.upload.clearFiles()
            }
        })

    },

    },




        }

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值