zoukankan      html  css  js  c++  java
  • element upload 上传报错 Uncaught TypeError: Cannot set property 'status' of undefined

    报错原因:设置了:file-list="fileList",filelist为只读,修改后就会报错 Cannot set property 'status' of undefined
    解决方法:在成功回调中用setTimeout清空上传列表即可解决。
    代码如下

     <el-upload  style="margin:10px 0 0 0;90%"  class="upload-demo" ref="upload" :on-success="success" :action='url"' :data="icon" :auto-upload="false" accept=".jpg, .png, .jpeg" :headers="headers" :on-change="onchangeupload" :on-remove="onremove" :file-list="fileList">
                <el-button slot="trigger" size="small" type="primary">{{$t('message.SelectFile')}}</el-button>
            </el-upload>
    
    //成功回调
    uploadsuccess (res) {
          if (res.code == "200") {
            this.$message({
              showClose: true,
              message: res.message,
              type: "success"
            })
    //-----------------------------------
    //解决关键代码:使用延时器清空上传文件列表和自定义参数,
          setTimeout(()=>{
            this.uploadfile=false
            this.icon={}
            this.$refs.upload.clearFiles()
          },100)
    //------------------------------------
          } else {
            this.$message({
              showClose: true,
              message: res.message,
              type: "error"
            })
          }
    
        },
    //失败回调
        uploaderror (res) {
          this.$message({
            showClose: true,
            message: res.message,
            type: "error"
          })
        },
    //打开弹框
          showUploadLogShow(val){
            this.uploadLog=true
            this.isUpload=val.isUpload
            this.fileTypeobj={
              fileType:"licenseFile",
              fileId:val.fileId,
              id:val.id
            }
          },
    //删除文件回调
     onremove(val,list){
            if(list.length==0){
              this.uploadfile=false
            }else{
              this.uploadfile=true
            }
          },
          onchangeupload(val,list){
            this.fileList = list.slice(-1);//只上传一个文件,自动更换最新选择文件
            if(list.length==0){
              this.uploadfile=false
            }else{
              this.uploadfile=true
            }
          },
    //触发上传
          trueload() { 
            if(this.uploadfile){
               if(this.isUpload){ 
               this.$confirm(this.$t('message.xukewenjaincunzai'),this.$t('message.Tips'), {
                    confirmButtonText:this.$t('message.Ok'),
                    cancelButtonText: this.$t('message.Cancel'),
                    type: 'warning'
                  }).then(() => {
                      this.$refs.upload.submit()
                        this.uploadLog = false
                        this.getData()
                }).catch(()=>{
                      this.$message({
                        showClose: true,
                        message:this.$t('message.Cancelupload'),
                      })
                      this.uploadLog = false
                    })
                }else{
                  this.$refs.upload.submit()
                  this.uploadLog = false
                  this.getData()
              }
            }else{
              this.$message({
                  showClose: true,
                  message:this.$t('message.Pleaseselectuploadfile'),
                  type: "error"
                })
            }
          },
    
    
    
    
  • 相关阅读:
    DBCP,C3P0与Tomcat jdbc pool 连接池的比较
    MySQL:创建、修改和删除表
    MySQL添加用户、删除用户与授权
    王垠 :写给支持和反对《完全用Linux工作》的人们 ( 2004/8/26)
    王垠:完全用Linux工作 (2003)
    王垠:什么是“对用户友好”(2012/05/18)
    顿悟:Linux是拿来用的,不是拿来折腾的
    《从零开始搭建游戏服务器》MySQL安装配置
    ehcache 缓存
    servlet
  • 原文地址:https://www.cnblogs.com/FormerWhite/p/12486411.html
Copyright © 2011-2022 走看看