• ElementUI实现手动上传


    在做项目中,与同事遇到问题,顺手记录一下

    <template>
      <div class="common-layout">
       <el-button size="mini" type="primary" @click="uploadOpen" >
     上传测试文件
    </el-button>
    <!-- 弹框 -->
    <el-dialog
      title="上传测试文件"
      :visible.sync="uploadVisible"
      width="60%"
      :close-on-click-modal="false"
    >
      <el-form ref="uploadform" 
          :model="uploadform" 
          label-width="110px" 
          :label-position="labelPosition" 
          size="small"
      >
        <el-form-item label="上传测试文件" prop="docType.crFile" ref="crFile">
          <el-upload
            ref="doctypeCrfile"
            :file-list="uploadform.docType.crFile"
            :data="{text:'测试数据'}"
            :auto-upload="false"
            action="/api/videoTranscribe?languageCode=en-US"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
             multiple
            :limit="9999"
            :on-exceed="handleExceed"
            :on-success="handleSuccess"
          >
            <el-button size="mini" type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="uploadConfirm">确 定</el-button>
        <el-button size="mini" @click="uploadVisible= false">关 闭</el-button>
      </span>
    </el-dialog>
    
      </div>
    </template>
    <script>
    export default {
      data() {
        return {
          uploadVisible: false,
          labelPosition: "left",
          uploadform:{
            docType: {
              crFile: []
            }
          },
        }
      },
      methods: {
        uploadOpen(){
          var vm = this;
          vm.uploadform.docType.crFile=[];
          vm.uploadVisible= true;
        },
        handleRemove(file, fileList) {
          console.log(file, fileList);
          for (var i = 0; i < this.fileList.length; i++) {
            if (this.fileList[i].uid == file.uid) {
              this.fileList.splice(i, 1);
              break;
            }
          }
        },
        handleExceed(files, fileList) {
          this.$message.warning(`最多上传 ${this.limit} 个文件`);
        },
           beforeRemove(file, fileList) {
          if (this.Qualified == "") {
            return this.$confirm(`确定移除 ${file.name}?`);
          } else if (this.Qualified == "1") {
            return true;
          }
        },
        // 上传测试文件
        uploadConfirm(){
          var vm = this;
          vm.$refs.doctypeCrfile.submit();
        },
        handleSuccess(response){
          if(response.code==200){
            this.$message.success('上传成功');
            this.uploadVisible=false;
          }
        },
      }
    }
    </script>
    <style lang="scss" scoped>
    
    </style>

    参考链接:

    https://blog.csdn.net/yangwqi/article/details/101520826

  • 相关阅读:
    Web应用指纹识别
    同步I/O 和 异步I/O
    怎样找出自己定义标签的java类
    Android多线程文件下载器
    cocos2d-x 3.0游戏实例学习笔记 《跑酷》 第三步---主角开跑&amp;同一时候带着刚体
    记C++课程设计--学生信息管理系统
    iOS开发--从TQRichTextViewDemo中学会分析project
    九度oj题目&amp;吉大考研10年机试题全解
    setOnFocusChangeListener的使用
    查看网络port占用
  • 原文地址:https://www.cnblogs.com/lxz123/p/16417038.html
Copyright © 2020-2023  润新知