手动上传与清除

手动上传与清除_第1张图片

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

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

   ----html
              
                    
                

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

    },

    },




        }

你可能感兴趣的:(javascript,前端,开发语言)